Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

javascript - Javascript相当于PHP Explode()(Javascript Equivalent to PHP Explode())

I have a string that looks like this:(我有一个看起来像这样的字符串:)

0000000020C90037:TEMP:data(0000000020C90037:TEMP:数据) And I need to grab everything after the first colon, so that I have TEMP:data.(我需要在第一次冒号之后抓住所有内容,以便我有TEMP:数据。) I don't often work in Javascript, if it were PHP I would do this:(我不经常使用Javascript,如果它是PHP我会这样做:) $str = '0000000020C90037:TEMP:data'; $arr = explode(":", $str); $var = $arr[1].":".$arr[2];   ask by Doug Molineux translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a direct conversion from your PHP code:(这是从PHP代码直接转换:)

//Loading the variable var mystr = '0000000020C90037:TEMP:data'; //Splitting it with : as the separator var myarr = mystr.split(":"); //Then read the values from the array where 0 is the first //Since we skipped the first element in the array, we start at 1 var myvar = myarr[1] + ":" + myarr[2]; // Show the resulting value console.log(myvar); // 'TEMP:data'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...