473,373 Members | 1,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 software developers and data experts.

parse string to display items

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
Jul 23 '05 #1
13 14065
Dropstengel wrote on 17 aug 2004 in comp.lang.javascript:
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(/,([^,]+)$/,' and $1')

alert(s)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
Dropstengel <ik@haat.spam> wrote:

Both your From and Reply-To addresses do not specify mailboxes which is
aviolation of Internet/Usenet standards and disregarding the Netiquette
s well as most certainly a violation of the Acceptable Use Policy of your
service provider. You have been warned.
I have a string that contains n items. Each item start with a '@' and the
item itself does not contains the '@a'. ^^ Is this a typo?
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?


Assuming that the above is a typo:

var
s = "@one@two@three@four",
i = s.lastIndexOf("@");

[s.substring(1, i).split("@").join(", "), s.substr(i + 1)].join(" and ")
PointedEars
--
So, somebody DOES read these!
Jul 23 '05 #3
Dropstengel <ik@haat.spam> wrote:

Both your From and Reply-To addresses do not specify mailboxes which is
a violation of Internet/Usenet standards and disregarding the Netiquette
as well as most certainly a violation of the Acceptable Use Policy of
your service provider. You have been warned.
I have a string that contains n items. Each item start with a '@' and the
item itself does not contains the '@a'. ^^ Is this a typo?
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?


Assuming that the above is a typo:

var
s = "@one@two@three@four",
i = s.lastIndexOf("@");

[s.substring(1, i).split("@").join(", "), s.substr(i + 1)].join(" and ")
PointedEars
--
So, somebody DOES read these!
Jul 23 '05 #4

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Dropstengel wrote on 17 aug 2004 in comp.lang.javascript:
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(/,([^,]+)$/,' and $1')

alert(s)

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

Evertjan, bedankt (thanks)
Now I see that it is quit simple....
It is an accident that I code something up in JavaScript...
Frank
Jul 23 '05 #5

"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:14****************@PointedEars.de...
Dropstengel <ik@haat.spam> wrote:

Both your From and Reply-To addresses do not specify mailboxes which is
a violation of Internet/Usenet standards and disregarding the Netiquette
as well as most certainly a violation of the Acceptable Use Policy of
your service provider. You have been warned.
Do you warn everybody?


PointedEars
--

Frank
Jul 23 '05 #6
On Tue, 17 Aug 2004 21:08:07 +0200, Dropstengel <ik@haat.spam> wrote:

[snipped drivel on munged addresses]
Do you warn everybody?


Unfortunately, yes, he does. Most people just ignore it and move on to the
useful things he says. I suggest you do the same. :)

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #7
Dropstengel wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
Dropstengel <ik@haat.spam> wrote:
Both your From and Reply-To addresses do not specify mailboxes which is
a violation of Internet/Usenet standards and disregarding the Netiquette
as well as most certainly a violation of the Acceptable Use Policy of
your service provider. You have been warned.


Do you warn everybody?


Almost everybody who perpetrates this violation. If I take the time
and the *continuing* behavior is also a violation of the Acceptable
Use Policy of the respective service provider's AUP, the SP is informed
about the case of network abuse in a formal complaint. The respective
poster is always killfiled on NetNews with its invalid From (so that
their postings are no longer filtered if they changed it to something
that is in accordance with the Net's standards/the Netiquette).
F'up2 PointedEars, Score adjusted
--
All I wanted was a little bit of time to myself. Then they started
mozilla.org. Bastards.
Jul 23 '05 #8
Dropstengel wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
Dropstengel <ik@haat.spam> wrote:
Both your From and Reply-To addresses do not specify mailboxes which is
a violation of Internet/Usenet standards and disregarding the Netiquette
as well as most certainly a violation of the Acceptable Use Policy of
your service provider. You have been warned.


Do you warn everybody?


Almost everybody who perpetrates this violation. If I take the time and
the *continuing* behavior is also a violation of the Acceptable Use Policy
of the respective service provider, the SP is informed about the case of
network abuse in a formal complaint. The respective posters are always
killfiled on NetNews with their invalid From (so that their postings are no
longer filtered if they changed it to something that is in accordance with
the Net's standards/the Netiquette).
F'up2 PointedEars, Score adjusted
--
All I wanted was a little bit of time to myself. Then they started
mozilla.org. Bastards.
Jul 23 '05 #9

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opscv5h7fhx13kvk@atlantis...
On Tue, 17 Aug 2004 21:08:07 +0200, Dropstengel <ik@haat.spam> wrote:

[snipped drivel on munged addresses]
Do you warn everybody?
Unfortunately, yes, he does. Most people just ignore it and move on to the
useful things he says. I suggest you do the same. :)


Yes, I'd love to..thanks.
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail


Frank
Jul 23 '05 #10
Dropstengel wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:14****************@PointedEars.de...
Dropstengel <ik@haat.spam> wrote:

Both your From and Reply-To addresses do not specify mailboxes which is
a violation of Internet/Usenet standards and disregarding the Netiquette
as well as most certainly a violation of the Acceptable Use Policy of
your service provider. You have been warned.

Do you warn everybody?


Nah, he only warns those that he notices. And when pressed, he cites an
article that is outdated and totally rubbish. I have asked several times
(of him) to explain the difference between a From address that does not
specify a mailbox and a From address that specifies a mailbox that can
not recieve email. In either case, you can't email the person. I guess
he has never explained it because he can't grasp the simple idea "It
doesn't matter".

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #11
JRS: In article <41***********************@news.xs4all.nl>, dated Tue,
17 Aug 2004 21:08:07, seen in news:comp.lang.javascript, Dropstengel
<ik@haat.spam> posted :

"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:14****************@PointedEars.de...
Dropstengel <ik@haat.spam> wrote:

Both your From and Reply-To addresses do not specify mailboxes which is
a violation of Internet/Usenet standards and disregarding the Netiquette
as well as most certainly a violation of the Acceptable Use Policy of
your service provider. You have been warned.


Do you warn everybody?


Unfortunately, more or yes less. The Germans have not entirely lost the
offensive habits displayed in 1914 ff and 1933 ff.

IMHO, the nicer ones need to explain to Lahn the error of his ways.

--
John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.

In MS OE, choose Tools, Options, Send; select Plain Text for News and E-mail.
Jul 23 '05 #12
Dropstengel wrote:
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

"@one@two@three@four".substring(1).split("@").join (",")

Mick
Jul 23 '05 #13
"Dropstengel" <ik@haat.spam> wrote in message news:<41***********************@news.xs4all.nl>...
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

The easiest way to do this, I think, is with a regex.
Then, do your split() as normal.

Shawn

Tested code:

<script type="text/javascript">

myString = '@one@two@three@four';
myString = myString.replace(/^@(.*)$/, '$1');
alert(myString);

</script>
Jul 23 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and I need to parse strings that look similar to the one below. All 5 rows will make up one string. I have a form where a use can copy/paste data like what you...
9
by: Python.LeoJay | last post by:
Dear all, i need to parse billions of numbers from a file into float numbers for further calculation. i'm not satisfied with the speed of atof() function on my machine(i'm using visual c++ 6)....
3
by: SharpCoderMP | last post by:
i've run into some trouble using data from xml inside my app. the scenario is simple. input data looks more or less like this: <item> <name>MyName</name> <somefloat>11.5</somefloat> </item> ...
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
1
by: vinayg | last post by:
how can i search subcategory wise for a particular category,i want to display items.suppose user selected a particular category.I want to display all items in that category + its subcategories. ...
0
by: daisies | last post by:
Hi Everyone, I'm new to java and to web development. I need to know how to display items of an arraylist in a h:datatable to look like this: ---------------------------- | item1 | item2 |...
2
by: Mika M | last post by:
Hi, Just for fun I'm trying to parse my GPS position string using C# 2005. When my code is trying to parse latitude string to double value like... double.Parse(items); // items = "6215.1058"...
2
by: hsachdevah | last post by:
Hi, I developed an application for my study project to do some mathematical calculations. In this application, I am reading from a text file which contains some numbers. Now the problem is...
0
by: anoop s | last post by:
Hi, How to display items of completion list of ajax autocompleteextender one at a row. Now it is displaying two or three according to the size of items in a row. thanks
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.