Remove commas from end of string

D

Dooza

Using ASP/VB I need to remove unwanted commas from the end of a field
that will be use in an array. There are items in the field that are
comma separated, so I don't want to remove them, just the end ones,
could be anywhere up to 5 unwanted commas.

Any ideas?

Cheers,

Steve
 
D

Dooza

Dooza said:
Using ASP/VB I need to remove unwanted commas from the end of a field
that will be use in an array. There are items in the field that are
comma separated, so I don't want to remove them, just the end ones,
could be anywhere up to 5 unwanted commas.

Any ideas?

Cheers,

Steve

In case anyone needs to do this, here is what I found:

function ctrim(str,trimstr)
while trim(left(str,1))=trimstr
str=trim(right(str,Len(str)-1))
wend
while trim(right(str,1))=trimstr
str=trim(Left(str,Len(str)-1))
wend
ctrim=str
end function

<%
str=",,a,b,c,"
Response.write ctrim(str,",")
%>

Steve
 
E

Evertjan.

Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:
Using ASP/VB

I suppose ASP/VBS?
I need to remove unwanted commas from the end of a field
that will be use in an array. There are items in the field that are
comma separated, so I don't want to remove them, just the end ones,
could be anywhere up to 5 unwanted commas.

<% ' vbscript
dim s
s = "blah, blah, blah,,,,,"
response.write endCommasAway(s)
%>

<script language='jscript' runat='server'>
function endCommasAway(x){ return x.replace(/,*$/,''); };
</script>
 
D

Dooza

Evertjan. said:
Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:


I suppose ASP/VBS?

Is there anything else I could have meant? No offence intended, but I at
least I tried :)
<% ' vbscript
dim s
s = "blah, blah, blah,,,,,"
response.write endCommasAway(s)
%>

<script language='jscript' runat='server'>
function endCommasAway(x){ return x.replace(/,*$/,''); };
</script>

Is this using regular expressions? One day I will get around to learning
it, as it seems to be very popular. Could you explain what its doing?

Cheers,

Steve
 
E

Evertjan.

Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:
Is there anything else I could have meant? No offence intended, but I
at least I tried :)

Well, either ASP or VB.

Why offence?
Is this using regular expressions? One day I will get around to
learning it, as it seems to be very popular. Could you explain what
its doing?

Better start experimenting with regex and reading a tutorial
and perhaps some specs, if all else fails.

<http://www.google.com/search?q=regex tutorial>
 
B

Bob Barrows [MVP]

Dooza said:
In case anyone needs to do this, here is what I found:

function ctrim(str,trimstr)
while trim(left(str,1))=trimstr
str=trim(right(str,Len(str)-1))
wend
while trim(right(str,1))=trimstr
str=trim(Left(str,Len(str)-1))
wend
ctrim=str
end function

<%
str=",,a,b,c,"
Response.write ctrim(str,",")
%>
str=",,a,b,c,"
Much more simply:
a=split(str(",") 'create array by splitting str on commas
str=join(a,",") 'create str by joining array elements with commas
Response.write ctrim(str,",")
 
D

Dooza

Evertjan. said:
Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:


Well, either ASP or VB.

Surely stating ASP and VB in an ASP newsgroup would mean that I want to
use ASP and VBScript, but I can see why it *could* be seen as me saying
I am using ASP and Visual Basic.
Why offence?

Because I didn't want to offend, I was being polite.
Better start experimenting with regex and reading a tutorial
and perhaps some specs, if all else fails.

Fair enough, another item on my to do list :)

Steve
 
D

Dooza

Bob said:
str=",,a,b,c,"
Much more simply:
a=split(str(",") 'create array by splitting str on commas
str=join(a,",") 'create str by joining array elements with commas
Response.write ctrim(str,",")
Hi Bob,
I am currently using this:
firstname = Split(ctrim(Session("firstname"),","),",")

Steve
 
B

Bob Barrows [MVP]

Dooza said:
Because I didn't want to offend, I was being polite.

You have failed to answer the question he asked, but it's
understandable. Instead of "Why offence", the question should have been
worded: "why did you assume I was offended?"

The answer: Evertjian's terse replies are often interpreted as being the
result of annoyance, rather than the desire to pack the maximum amount
of information into as few words as possible, with the additional
limitation that English is not his native language.
I will say again (for those that missed it the first time): beware of
attempting to read emotion into text messages.
 
D

Dooza

Bob said:
You have failed to answer the question he asked, but it's
understandable. Instead of "Why offence", the question should have been
worded: "why did you assume I was offended?"

The answer: Evertjian's terse replies are often interpreted as being the
result of annoyance, rather than the desire to pack the maximum amount
of information into as few words as possible, with the additional
limitation that English is not his native language.
I will say again (for those that missed it the first time): beware of
attempting to read emotion into text messages.

Hi Bob, I have noted your comments on previous occasion, so knew it was
a language thing, I tried to reply as best I could.

Evertjian, I didn't assume you were offended, I actually meant that I
didn't want to offend you in the reply I was making...maybe I need to
brush on my English :)

Steve
 
E

Evertjan.

Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:
Evertjian, I didn't assume you were offended, I actually meant that I
didn't want to offend you in the reply I was making...maybe I need to
brush on my English :)

Hi Steve,

I am not that easily offended.

Since you are possibly new to Usenet or this NG: questions are not always
what they seem, but are ment to keep the record straight for other
readers.

So talking about VB in asp needs correction, because many need to know
the difference reading the postings now or later from the archive. That
does not mean I think you personally don't know the difference.

Usenet posting is not emailing but more like broadcasting, and in a radio
talk the visitor is not answering only to the curiosity of the host,
as both questions and answers have information impact on others.

Further more, this is an international NG, so the niceties of local
English slang are largely wasted and should not be expected. English is
just a tool for communication.

Which should not mean a joke now and then is wasted on this NG, as I see
it.

Do you know the story of the Rabbi and the response object?
 
D

Dooza

Evertjan. said:
Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:


Hi Steve,

I am not that easily offended.

Since you are possibly new to Usenet or this NG: questions are not always
what they seem, but are ment to keep the record straight for other
readers.

I am a relative newbie, I started in 1997 in the macromedia newsgroups,
its where I learnt my trade. Also I was a regular user at uk.music.rave
for many years until the popularisation of forums.
So talking about VB in asp needs correction, because many need to know
the difference reading the postings now or later from the archive. That
does not mean I think you personally don't know the difference.

Usenet posting is not emailing but more like broadcasting, and in a radio
talk the visitor is not answering only to the curiosity of the host,
as both questions and answers have information impact on others.

Further more, this is an international NG, so the niceties of local
English slang are largely wasted and should not be expected. English is
just a tool for communication.

Which should not mean a joke now and then is wasted on this NG, as I see
it.

I do see what your saying, using the correct netiquete is something I
thought I had cracked, but not using a truly international newsgroup
like this, where the topic is very specific, I still need to be careful.
Do you know the story of the Rabbi and the response object?

No I dont...

Steve
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top