简体   繁体   中英

How to turn a string into an array under a specific delimiter

I have this string in javascript:

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

how can make this string as an array with a length equal to 4 example:

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

Use split(..)

st.split(",")

Outputs:

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

This would give you an array of four string elements

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

so for example

        stArray[1]

would return "cd"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM