Javascript字串對象的常用方法簡明版

來源:互聯網
上載者:User

var a = "abcDEfGgdefg32asdf38";document.write("原始:"+a+"<br />")document.write("粗體:"+a.bold()+"<br />");document.write("大號:"+a.big()+"<br />");document.write("斜體:"+a.italics()+"<br />");document.write("刪除線:"+a.strike()+"<br />");document.write("字型大小:"+a.fontsize(10)+"<br />");document.write("字型顏色:"+a.fontcolor("#ff0000")+"<br />");document.write("上標:"+a.sup()+"<br />");document.write("下標:"+a.sub()+"<br />");document.write("大寫:"+a.toUpperCase()+"<br />");document.write("大寫:"+a.toLowerCase()+"<br />");document.write("返回索引字元:"+a.charAt(3)+"<br />");//這裡應該是"D"document.write("返回索引:"+a.indexOf("f")+"<br />");//這裡應該是5document.write("返回索引(逆向尋找):"+a.lastIndexOf("f")+"<br />");//這裡應該是9document.write("尋找字串:"+a.search("f")+"<br />");//這裡應該是5,與indexOf相同document.write("替換字串:"+a.replace("a","A")+"<br />");//把字串中的a替換成Adocument.write("返回子串:"+a.slice(1,3)+"<br />");//應該是bc,返回從索引1到3-1的子串document.write("分割字串:"+a.split("D").toString()+"<br />");//把D作為分割符,分割字串,返回數組document.write("返回子串:"+a.substr(1,2)+"<br />");//返回子串,從索引1開始,長度為2,這裡就是bcdocument.write("返回子串:"+a.substring(1,3)+"<br />");//與sclice()相同,返回索引1到3-1的子串document.write("匹配:"+a.match(/\d+/)+"<br />");//正則匹配,返回匹配的結果,這裡是32

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.