String 对象用于处理文本(字符串),有很多方法,刻意很难记住,不记还总是忘,上笔记!

笔记代码:

var txt="Hello world!"
var txt2 = "你好JS"
// String 常用方法 
//字符串样式
 
document.write("<p>big:加大"+txt.big()+"</p>")
document.write("<p>Small:缩小" + txt.small() + "</p>")
document.write("<p>bold:加粗"+txt.bold()+"</p>") 
document.write("<p>Italic:倾斜 " + txt.italics() + "</p>")
document.write("<p>link:链接"+txt.link("http://www.baidu.com")+"</p>")
document.write("<p>Strike:删除线 " + txt.strike() + "</p>")
document.write("<p>Fontcolor:字体颜色 " + txt.fontcolor("Red") + "</p>")
document.write("<p>Fontsize:字体大小,值为1~7" + txt.fontsize(4) + "</p>")
document.write("<p>Lowercase:小写" + txt.toLowerCase() + "</p>")
document.write("<p>Uppercase:大写" + txt.toUpperCase() + "</p>")
document.write("<p>Subscript:下标" + txt.sub() + "</p>")
document.write("<p>Superscript:上标" + txt.sup() + "</p>")
//处理字符串
 
document.write("<p>concat:多项字符拼接" + txt.concat(txt2) + "</p>") 
document.write("<p>split:分割成字符串数组" +txt.split("")  + "</p>")
document.write("<p>slice:从n到m处截取" +txt.slice(6)  + "</p>")
document.write("<p>match字符:匹配一次,成功返回字符,否则null" +txt.match("world") + "</p>")
document.write("<p>match正则:匹配一次,成功返回字符,否则null" +txt2.match(/\w+/g) + "</p>")
document.write("<p>replace字符替换:" +txt.replace("world","JS") + "</p>")
document.write("<p>replace正则替换:" +txt2.replace(/\w+/g,"**") + "</p>")
document.write("<p>search检索字符,成功返回所在索引,否认返回-1:" +txt2.search(/js/) + "</p>")
document.write("<p>search检索字符,成功返回所在索引,否认返回-1:" +txt2.search(/js/i) + "</p>")

  
document.write("<p>不常用:</p>") 
document.write("<p>anchor:a标签name属性"+txt.anchor("hhh")+"</p>")
document.write("<p>blink文本闪烁-无效:"+txt.blink()+"</p>")