By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

Remove commas from end of string

P: n/a
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
Jan 8 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Dooza wrote:
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
Jan 8 '08 #2

P: n/a
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>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 8 '08 #3

P: n/a
Evertjan. wrote:
Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:
>Using ASP/VB

I suppose ASP/VBS?
Is there anything else I could have meant? No offence intended, but I at
least I tried :)
>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>
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
Jan 8 '08 #4

P: n/a
Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:
Evertjan. wrote:
>Dooza wrote on 08 jan 2008 in
microsoft.public.inetserver.asp.general:
>>Using ASP/VB

I suppose ASP/VBS?

Is there anything else I could have meant? No offence intended, but I
at least I tried :)
Well, either ASP or VB.

Why offence?
>
>>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>

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%20tutorial>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 8 '08 #5

P: n/a
Dooza wrote:
Dooza wrote:
>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,",")
%>
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,",")

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 8 '08 #6

P: n/a
Evertjan. wrote:
Dooza wrote on 08 jan 2008 in microsoft.public.inetserver.asp.general:
>Evertjan. wrote:
>>Dooza wrote on 08 jan 2008 in
microsoft.public.inetserver.asp.general:

Using ASP/VB
I suppose ASP/VBS?
Is there anything else I could have meant? No offence intended, but I
at least I tried :)

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.
>>>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>
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.
Fair enough, another item on my to do list :)

Steve
Jan 8 '08 #7

P: n/a
Bob Barrows [MVP] wrote:
Dooza wrote:
>Dooza wrote:
>>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,",")
%>
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
Jan 8 '08 #8

P: n/a
Dooza wrote:
>Why offence?

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.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 8 '08 #9

P: n/a
Bob Barrows [MVP] wrote:
Dooza wrote:
>>Why offence?
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.
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
Jan 8 '08 #10

P: n/a
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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 8 '08 #11

P: n/a
Evertjan. wrote:
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.
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
Jan 9 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.