SOURCE

//字符串  
 function writeDocument(variable) {
    document.write(variable + "<br/>");
} 


var astrimg="Hello";
document.write(astrimg+'<br/>');
document.write(astrimg.length+'<br/>');
document.write(astrimg.toLocaleUpperCase()+'<br/>');
document.write(astrimg.toUpperCase()+'<br/>');
document.write(astrimg.toLowerCase()+'<br/>');
document.write(astrimg.charAt(2)+'<br/>');
document.write(astrimg.charAt(4)+'<br/>');
document.write(astrimg.substring(3)+'<br/>');
document.write(astrimg.substring(0,2)+'<br/>');

writeDocument("//replace..............***.....................")
var sentence="We have fun in our class,Do you have fun in your class?";
writeDocument(sentence);
writeDocument(sentence.replace("class","you"));
writeDocument(sentence.replace(/class/g,"programming you"));

writeDocument("//split................***...................")
var splitsentence="We have fun in class";
writeDocument(splitsentence);
writeDocument(splitsentence.split(" "));//空格
writeDocument(splitsentence.split(""));
writeDocument(astrimg.split(" "));
writeDocument(astrimg.split(""));

writeDocument(sentence.indexOf("class"));
writeDocument(sentence.lastIndexOf("class"));

//如何找出字符串“Can you can a can as a Canner can can a can”中找出所有c的个数,
//不区分大小写。 
 function countChar(stringValue,char){
     var asentence="Can you can a can as a Canner can can a can";
     var j=0;
     for(var i=0;i<asentence.length;i++){
         var char=asentence.charAt(i);//统计位置数
         if(char.toLowerCase()=="c"){
             j=j+1;
         }
     }
     return j;
 }
 var y;
 y=countChar();
 writeDocument("字母c的个数是"+y+'</br>');

//统计字符串中有多少个数字
function countNumber(stringtoCount) {
var numCount=0;
for(var i=0;i<stringtoCount.length;i++){
var char=stringtoCount.charAt(i);
//isNaN()对空格字符会转化为0,需要加个判断charAt(1)不能为
if(char!=""&!isNaN(char)){
numCount++;
}
}
return numCount;
}
document. write("这个字符串中的数字个数为"+countNumber("26vdsd4wd15885cdwc"));


console 命令行工具 X clear

                    
>
console