javascript中有没有现成的函数可以解析字符串“北京,郑州,武汉,杭州,上海”成单个地名

cxz7531 2003-11-24 06:10:42
在delphi java中都可以,但javascript中一直没有找到?那位仁兄提供一点经验
...全文
111 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
supere 2003-11-24
  • 打赏
  • 举报
回复
str = "北京,郑州,武汉,杭州,上海"
arr = str.split(",")
for (var i=0;i<arr.length;i++)
alert(arr[i]);

alert(arr.join(","));
kingdomzhf 2003-11-24
  • 打赏
  • 举报
回复
split Method
See Also
concat Method | RegExp Object | Regular Expression Object | Regular Expression Syntax | String Object Methods

Applies To: String Object
Requirements
Version 3
Returns the array of strings that results when a string is separated into substrings.

stringObj.split([separator[, limit]])
Arguments
stringObj
Required. The String object or literal to be split. This object is not modified by the split method.
separator
Optional. A string or an instance of a Regular Expression object identifying one or more characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
limit
Optional. A value used to limit the number of elements returned in the array.
Remarks
The result of the split method is an array of strings split at each point where separator occurs in stringObj. The separator is not returned as part of any array element.

Example
The following example illustrates the use of the split method.

function SplitDemo(){
var s, ss;
var s = "The rain in Spain falls mainly in the plain.";
// Split at each space character.
ss = s.split(" ");
return(ss);
}
whisht 2003-11-24
  • 打赏
  • 举报
回复
split
hrong 2003-11-24
  • 打赏
  • 举报
回复
"北京,郑州,武汉,杭州,上海".split(",")

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧