function writeDocument(variable) {
document.write(variable + "<br/>");
}
var str="welcome";
writeDocument(str.charAt(2));
writeDocument(str.charAt(6));
writeDocument(str.substring(3));
writeDocument(str.substring(0,2));
var sence="we have fun in class.Do you have fun in class";
writeDocument(sence);
writeDocument(sence.replace("have","had"));
writeDocument(sence.replace(/class/g,"there"));
var abbd="we have fun in class";
writeDocument(abbd);
writeDocument(abbd.split(""));
writeDocument(abbd.split(" "));
writeDocument(sence.split("."));
writeDocument(sence.indexOf("class"));
writeDocument(sence.lastIndexOf("class"));
var string="Can you can a can as a Canner can can a can";
function count(str,char)
{
var s=0;
for(var i=0;i<str.length;i++)
{
var ca=str.charAt(i);
if(ca.toLowerCase()=="c")
{
s++;
}
}
return s;
}
writeDocument(count(string,"c"));
function countNumber(stringtoCount) {
var numCount = 0;
for(var i=0;i<stringtoCount.length;i++){
if(isNaN(stringtoCount.substring(i,i+1))==false){
numCount++
}
}
return numCount;
}
var numC="zxc231sd2fe4dv2g"
document.write(numC+"<br>")
document.write("字符串中有"+countNumber(numC)+"个数字"+"<br>")
console