function write(a) {
document.write(a + "<br/>");
}
var b= "welcome";
write(b);
write(b.length);
write(b.toLowerCase());
write(b.toUpperCase());
write(b.charAt(2));
write(b.charAt(6));
write(b.substring(3));
write(b.substring(0, 2));
var sen = "We have fun in our class. Do you have fun in your class?"
write(sen);
write(sen.replace("class", "programming class"));
write(sen.replace(/class/g, "programming class"));
var split = "We have fun in our class";
write(split);
write(split.split(" "));
write(sen.split(""));
write(sen.indexOf("class"));
write(sen.lastIndexOf("class"));
write(sen.match("class"));
write(sen.match(/class/g));
write(sen.search(/class/g));
function countChar(stringValue, char){
var count = 0;
for (var i=0;i<stringValue.length; ++i){
if (stringValue.charAt(i).toLowerCase() == char) {
count++;
}
}
return count;
}
var stringValue = "Can you can a can as a Canner can can a can";
write("There are " + countChar(stringValue, "c") + " 'c' in sentence.");
//统计数字
function countNumber(stringtoCount){
var count = 0;
for (var i=0;i<stringtoCount.length; ++i){
if (isNaN(stringtoCount.charAt(i))== false) {
count++;
}
}
return count;
}
var stringtoCount = "abc1234567";
write("There are " + countNumber(stringtoCount) + " 'Number' in sentence.");
console