var welcomeString="Welcome";
document.write(welcomeString+"<br/>");
document.write(welcomeString.length+"<br/>");
document.write(welcomeString.toLowerCase()+"<br/>");
document.write(welcomeString.toUpperCase()+"<br/>");
document.write(welcomeString.charAt(2)+"<br/>");//获取第3个字符串
document.write(welcomeString.charAt(6)+"<br/>");
document.write(welcomeString.substring(3)+"<br/>");//截取字符串
document.write(welcomeString.substring(0,2)+"<br/>");
document.write('<br/>---------------------------------<br/>');
var sentence = "We have fun in class.Do you have fun in class?"
document.write(sentence+"<br/>");
document.write(sentence.replace("We","You")+"<br/>");//替换字符串(原字符串)
document.write(sentence.replace(/class/g,"programming class")+"<br/>");//替换字符串(正则表达式)
document.write('<br/>---------------------------------<br/>');
var splitSentence = "We have fun in our class";
document.write(splitSentence+"<br/>");
document.write(splitSentence.split(" ")+"<br/>");//空格切割
document.write(welcomeString+"<br/>");
document.write(welcomeString.split("")+"<br/>");//空字符切割
document.write(sentence.split("")+"<br/>");
document.write('<br/>---------------------------------<br/>');
document.write(sentence.indexOf("class")+"<br/>");
document.write(sentence.lastIndexOf("class")+"<br/>");
document.write(sentence.match(/class/g)+"<br/>");
document.write(sentence.search(/class/g)+"<br/>");
document.write('<br/>---------------------------------<br/>');
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";
document.write("字符串中含有" + countChar(stringValue,"c")+ "个字母c");
document.write('<br/>---------------------------------<br/>');
function countNumber(stringtoCount) {
var numCount = 0;
for(var i=0;i<stringtoCount.length;++i)
{
var char = stringtoCount.charAt(i);
//isNaN()对空格字符会转化为0,需要加个判断charAt(i)不能为空格
if (char != " " && !isNaN(char)) {
document.write(true);
// numCount++;
}else{
document.write(false);
}
}
return numCount;
}
//document.write("字符串中含有" +countNumber("3h4e4g9k8o")+"个数字");
console