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/>");
document.write(welcomeString.charAt(6) + "<br/>");
document.write(welcomeString.substring(3) + "<br/>");
document.write(welcomeString.substring(0,2) + "<br/>");
document.write('<br/>-------------------------------<br/>');
var setence = "We have fun in our class, Do you have fun class."
document.write(setence + "<br/>");
document.write(setence.replace("We","You") + "<br/>");
document.write(setence.replace("class","programming class") + "<br/>");
document.write('<br/>-------------------------------<br/>');
var splitSentence = "We have fun in our class";
document.write(splitSentence.split(" ") + "<br/>");
document.write(welcomeString + "<br/>");
document.write(welcomeString.split("") + "<br/>");
document.write(setence.split(""));
document.write('<br/>-------------------------------<br/>');
document.write(setence.indexOf("class") + "<br/>");
document.write(setence.lastIndexOf("class") + "<br/>");
document.write('<br/>-------------------------------<br/>');
function countchar(){
var str="Can you can a as can a Caner can can a can";
var n=0;
for(var i=0;i<str.length;i++){
var char = str.charAt(i);
if(char.toLowerCase()=="c"){
n+=1;
}
}
document.write("字符串中含有"+n+"个字母c");
}
countchar();
document.write('<br/>-------------------------------<br/>');
function countchar1(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 Caner can can a can";
document.write("There are"+countchar1(stringValue,"c")+"c")
document.write('<br/>-------------------------------<br/>');
function countNumber(stringtoCount){
var num=0;
for(var i=0;i<stringtoCount.length;i++){
var char=stringtoCount.charAt(i);
//isNaN()对空格字符会转化为0,需要加个判断charAt(1)不能为
if(char!=""&!isNaN(char)){
num++;
}
}
return num;
}
document. write("aa6541里面有" +countNumber("aa6541") + "个数字");
console