[JavaScript-String類]字串切割split第二篇 使用字串來切割字串, 如使用 "["、"]"、","、"."、"a"等字元及字串。 split("使用字元及字串"); 程式 <script type ="text/javascript"> str = "[JavaScript]字串切割split"; document.write("測試的字串為:"+str+"<br>"); var arr = new Array; arr = str.split("]"); document.write("split使用字串切割用  ] <br>"); for( i =0 ; i < arr.length;i++){ document.write("位置"+i+"為:"+arr[i]+"<br>"); } document.write("<br>"); document.write("------------------<br>"); str = "JavaScript,字串,切割,split"; document.write("測試的字串為:"+str+"<br>"); var arr = new Array; arr = str.split(","); document.write("split使用字串切割用  ,<br>"); for( i =0 ; i < arr.length;i++){ document.write("位置"+i+"為:"+arr[i]+"<br>"); } </script> 結果:

圖:

 

其它文章

文章標籤
全站熱搜
創作者介紹
創作者 PG Levin Li 的頭像
PG Levin Li

程式開發學習之路

PG Levin Li 發表在 痞客邦 留言(0) 人氣(1,550)