查了半天js,没找到同vbs中split函数功能(将字符串转化为数组)的js函数,故写了一个,方便大家,很简单,大家来看一下。

bubuy 2003-11-03 05:07:46
不知道js有此功能的函数没有,有,望大家给出。
没有的话,就试试我写的,虽然很简单,但是觉
的还好用,优化的话送分。谢谢大家。
...全文
186 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fason 2003-11-03
  • 打赏
  • 举报
回复
我是少用JScript,用javascript比较多
bubuy 2003-11-03
  • 打赏
  • 举报
回复
对了,大家喜欢把JScript和JavaScript
混在一起啊,其实这是两种不同的东西嘛
bubuy 2003-11-03
  • 打赏
  • 举报
回复
哦,哈哈,我就是说嘛,
我居然没看到,我猜也
是有的,怎么没翻到啊,
查了半天帮助,才下定
决心写的。唉~~js不
够熟啊。谢谢两位,这
下可好玩了。
kingdomzhf 2003-11-03
  • 打赏
  • 举报
回复
JScript Language Reference

--------------------------------------------------------------------------------

split Method
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);
}
fason 2003-11-03
  • 打赏
  • 举报
回复
晕~~

就是str.split(",")啊
bubuy 2003-11-03
  • 打赏
  • 举报
回复
调用:
var things=StrtoArray("bubuy,bubuy1,bubuy2",",")//表示以”,“为分割将字符串化为数组。
alert(things[0]+things[1]+things[2]);
bubuy 2003-11-03
  • 打赏
  • 举报
回复

function StrtoArray(str,chr)//字符化数组
{
var v,i,j,array;
i=0;
if((j=str.indexOf(chr))!=-1)array=new Array(str.substring(i,j));
else array=new Array(str);
while(j!=-1)
{
str=str.replace(chr,"");
i=j;
j=str.indexOf(chr);
if(j!=-1)v=new Array(str.substring(i,j))
else v=new Array(str.substring(i,str.length))
array=array.concat(v);
}
return array;
}

87,907

社区成员

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

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