2012-08-27 17 views
1

我有這個字符串中的JavaScript下:如何把字符串轉換成的陣列的特定定界符

var st="ab,cd,ef,gh"; 

如何使該字符串作爲具有等於4例的長度的數組:

st should be like this : [ab cd ef gh] 
+0

的[如何分割字符串可能重複的數組在JavaScript](http://stackoverflow.com/questions/1493407/how-to-split-a-string-in-javascript) –

回答

4

使用split(..)

st.split(",") 

輸出:

["ab", "cd", "ef", "gh"] 
0

這將給你四種弦元素

 var st="ab,cd,ef,gh"; 
     string[] stArray = st.Split(','); 

因此,例如

 stArray[1] 

將返回 「CD」

+0

符號'字符串[]'不是JavaScript這是什麼questi根據要求。此外,javscript字符串方法是split()'小寫字母S.我猜你正在指定其他語言。 – jfriend00