替换字符串
str =str.replace(/;/g, ",");//将分号替换成逗号
删除第一个字符
str=str.substr(1);//删除字符串第一个字符
删除最后一个字符
str=str.substring(0,str.length-1); //删除字符串最后一个字符
截取字符串
stringObject.substr(start [, length ])
php截取字符串
php //构造字符串 $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; echo "原字符串:".$str." "; //按各种方式进行截取 $str1 = substr($str,5); echo "从第5个字符开始取至最后:".$str1." "; $str2 = substr($str,9,4); echo "从第9个字符开始取4个字符:".$str2." "; $str3 = substr($str,-5); echo "取倒数5个字符:".$str3." "; $str4 = substr($str,-8,4); echo "从倒数第8个字符开始向后取4个字符:".$str4." "; $str5 = substr($str,-8,-2); echo "从倒数第8个字符开始取到倒数第2个字符为止:".$str5." "; ?>
匹配字符串
str.indexOf(value);