解析字符串以显示项目 [英] parse string to display items

查看:50
本文介绍了解析字符串以显示项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个包含n个项目的字符串。每个项目都以@开头,

项本身不包含@a。

例如字符串如下:" @ one @ two @ three @ four


我必须将此字符串输出为一,二,三和四。

所以实际上第一个''''可以删除,下一个除了最后一个替换

by,"最后一个单词是和。

有一种简单的方法吗?


Frank

Hi,

I have a string that contains n items. Each item start with a ''@'' and the
item itself does not contains the ''@a''.
For example the string looks like: "@one@two@three@four"

I have to output this string as "one, two, three and four".
So in fact the first ''@'' can be removed, the next except the last replaces
by ", " and the last one by the word "and ".
Is there a simple way doing this?

Frank

推荐答案

Dropstengel于2004年8月17日在comp.lang.javascript中写道
Dropstengel wrote on 17 aug 2004 in comp.lang.javascript:

我有一个包含n个项目的字符串。每个项目都以@开头,
项目本身不包含@a。
例如字符串看起来像:@ one @ two @ three @ four ;

我必须输出这个字符串为一,二,三和四。
所以实际上第一个''''可以删除,下一个除了最后一个
替换为,最后一个用和这个词。
是否有一个简单的方法呢?
Hi,

I have a string that contains n items. Each item start with a ''@'' and
the item itself does not contains the ''@a''.
For example the string looks like: "@one@two@three@four"

I have to output this string as "one, two, three and four".
So in fact the first ''@'' can be removed, the next except the last
replaces by ", " and the last one by the word "and ".
Is there a simple way doing this?




s =" @ one @ two @ three @ four"


s = s.substr(1).split(''@'')。join('','')。replace(/,([^,] +)



s = "@one@two@three@four"

s = s.substr(1).split(''@'').join('','').replace(/,([^,]+)


/,''和


1'')


alert(s)


-

Evertjan。

荷兰。

(请更改x''es我的电子邮件中的点数)
1'')

alert(s)

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


这篇关于解析字符串以显示项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆