parse string to display items

D

Dropstengel

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
 
E

Evertjan.

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)
 
T

Thomas 'PointedEars' Lahn

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
 
T

Thomas 'PointedEars' Lahn

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
 
D

Dropstengel

Evertjan. said:
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, bedankt (thanks)
Now I see that it is quit simple....
It is an accident that I code something up in JavaScript...
Frank
 
D

Dropstengel

Thomas 'PointedEars' Lahn said:
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
 
M

Michael Winter

[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
 
T

Thomas 'PointedEars' Lahn

Dropstengel said:
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
 
T

Thomas 'PointedEars' Lahn

Dropstengel said:
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
 
R

Randy Webb

Dropstengel said:
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".
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue,
17 Aug 2004 21:08:07, seen in Dropstengel
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.
 
M

Mick White

Dropstengel said:
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
 
S

Shawn Milo

Dropstengel said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top