Remove commas from end of string

Discussion in 'ASP General' started by Dooza, Jan 8, 2008.

  1. Dooza

    Dooza Guest

    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
     
    Dooza, Jan 8, 2008
    #1
    1. Advertising

  2. Dooza

    Dooza Guest

    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
     
    Dooza, Jan 8, 2008
    #2
    1. Advertising

  3. Dooza

    Evertjan. Guest

    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)
     
    Evertjan., Jan 8, 2008
    #3
  4. Dooza

    Dooza Guest

    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
     
    Dooza, Jan 8, 2008
    #4
  5. Dooza

    Evertjan. Guest

    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)
     
    Evertjan., Jan 8, 2008
    #5
  6. 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.
     
    Bob Barrows [MVP], Jan 8, 2008
    #6
  7. Dooza

    Dooza Guest

    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
     
    Dooza, Jan 8, 2008
    #7
  8. Dooza

    Dooza Guest

    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
     
    Dooza, Jan 8, 2008
    #8
  9. 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.
     
    Bob Barrows [MVP], Jan 8, 2008
    #9
  10. Dooza

    Dooza Guest

    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
     
    Dooza, Jan 8, 2008
    #10
  11. Dooza

    Evertjan. Guest

    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)
     
    Evertjan., Jan 8, 2008
    #11
  12. Dooza

    Dooza Guest

    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
     
    Dooza, Jan 9, 2008
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AviraM
    Replies:
    2
    Views:
    6,435
    Manish Pandit
    Sep 28, 2006
  2. James Kanze
    Replies:
    2
    Views:
    526
  3. R. David Murray
    Replies:
    8
    Views:
    604
    Tim Chase
    Mar 27, 2009
  4. Jason Lillywhite

    remove commas from string

    Jason Lillywhite, Aug 5, 2009, in forum: Ruby
    Replies:
    13
    Views:
    274
    Jason Lillywhite
    Aug 6, 2009
  5. Jame Pearl

    How can I remove trailing commas?

    Jame Pearl, Jan 30, 2006, in forum: Perl Misc
    Replies:
    21
    Views:
    1,256
Loading...

Share This Page