首页 > 技术文章 > javaScript 中的字符操作

1306962984wei 2020-07-07 15:15 原文

var str = "abc|ddd";
document.writeln(str.length+"<br/>");
//截取字符串substring
//分割字符串 split
//取到指定的字符charAt
//替换 replace
document.write(str.substring(2,4)+"<br/>");
document.write(str.split('|')+"<br/>");
document.write(str.charAt(2)+"<br/>");
document.write(str.replace(/d/g,"a")); // /g代表全部替换
document.write(str.replace("d","a")); //替换第一个

推荐阅读