function writeDocument(variable) {
document.write(variable + "<br/>");
}
var welcomeString="Welcome";
writeDocument(welcomeString);
writeDocument(welcomeString.length);
writeDocument(welcomeString.toLocaleLowerCase());
writeDocument(welcomeString.toLocaleUpperCase());
writeDocument("");
writeDocument(welcomeString.charAt(2));
writeDocument(welcomeString.charAt(6));
writeDocument("");
writeDocument(welcomeString.substring(3));
writeDocument(welcomeString.substring(0,2));
writeDocument("");
var sentence="We have fun in our class.Do you have fun in your class?";
writeDocument(sentence);
writeDocument(sentence.replace("We","you"));
writeDocument(sentence.replace(/class/g,"programming class")); //正则表达式,没有加g只替换第一个,加g都替换
writeDocument("");
var splitSentence="We have fun in our class";
writeDocument(splitSentence);
writeDocument(splitSentence.split(" "));// 空格字符
writeDocument(welcomeString);
writeDocument(welcomeString.split(""));// 空字符
writeDocument(sentence);
writeDocument(sentence.split("."));// . 字符
writeDocument("");
writeDocument(sentence.indexOf("class"));
writeDocument(sentence.lastIndexOf("class"));
writeDocument("");
function countChar(stringValue,char){
var charCount=0
for(var n;n<stringValue.length;n++){
if(stringValue.charAt(i).toLocaleLowerCase()==char){
++charCount;
}
}
return charCount;
}
var stringValue="Can you can a canas a Canner can can a can";
var char="c";
countChar(stringValue,char);
console