function writeDocument(variable) {
document.write(variable + "<br/>");
}
var welComeString="welcome";
writeDocument(welComeString);
writeDocument(welComeString.length);
writeDocument(welComeString.toLowerCase());
writeDocument(welComeString.toUpperCase());
writeDocument(welComeString.charAt(2));
writeDocument(welComeString.charAt(6));
writeDocument(welComeString.substring(3));
writeDocument(welComeString.substring(0,2));
var sentence="We have fun in our class. Do you have fun class?";
writeDocument(sentence);
writeDocument(sentence.replace("We","You"));
writeDocument(sentence.replace(/class/,"programming class"));
writeDocument(sentence.replace(/class/g,"programming class"));
var splitSentence="We have fun in our class. ";
writeDocument(splitSentence);
writeDocument(splitSentence.split(" "));//把单词分割
writeDocument(welComeString);//
writeDocument(welComeString.split(""));//把字母分割
writeDocument(sentence.split(""));//把句子分割
writeDocument("//Indexof--------------------------------------------------------");
writeDocument(sentence.indexOf("class"));//若找不到,返回-1;
writeDocument(sentence.lastIndexOf("class"));
writeDocument(sentence.match("class"));
writeDocument(sentence.match(/class/g));
writeDocument(sentence.search(/class/g));
//如何找出字符串“Can you can a can as a Canner can can a can”中找出所有c的个数,不区分大小写。
function countChar(stringValue,char){
var charCount=0;
for(var i=0;i<stringValue.length;i++){
if(stringValue.charAt(i).toLowerCase()==char){
++charCount;
}
}
return charCount;
}
var stringValue="Can you can a can as a Canner can can a can";
writeDocument("There are "+countChar(stringValue,"c")+" 'c' in sentence");
function co(s,c){
var cc=0;
for(var i=0;i<s.length;i++){
if(s.charAt(i).toLowerCase()==c){
++cc;
}
}
return cc;
}
var s="bananan nanana";
writeDocument("there are"+co(s,"a"));
console