Remove commas from end of string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dooza

    Remove commas from end of string

    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

    #2
    Re: Remove commas from end of string

    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,trims tr)
    while trim(left(str,1 ))=trimstr
    str=trim(right( str,Len(str)-1))
    wend
    while trim(right(str, 1))=trimstr
    str=trim(Left(s tr,Len(str)-1))
    wend
    ctrim=str
    end function

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

    Steve

    Comment

    • Evertjan.

      #3
      Re: Remove commas from end of string

      Dooza wrote on 08 jan 2008 in microsoft.publi c.inetserver.as p.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='jscri pt' runat='server'>
      function endCommasAway(x ){ return x.replace(/,*$/,''); };
      </script>

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

      Comment

      • Dooza

        #4
        Re: Remove commas from end of string

        Evertjan. wrote:
        Dooza wrote on 08 jan 2008 in microsoft.publi c.inetserver.as p.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='jscri pt' 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

        Comment

        • Evertjan.

          #5
          Re: Remove commas from end of string

          Dooza wrote on 08 jan 2008 in microsoft.publi c.inetserver.as p.general:
          Evertjan. wrote:
          >Dooza wrote on 08 jan 2008 in
          >microsoft.publ ic.inetserver.a sp.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.wri te endCommasAway(s )
          >%>
          >>
          ><script language='jscri pt' 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)

          Comment

          • Bob Barrows [MVP]

            #6
            Re: Remove commas from end of string

            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,trims tr)
            while trim(left(str,1 ))=trimstr
            str=trim(right( str,Len(str)-1))
            wend
            while trim(right(str, 1))=trimstr
            str=trim(Left(s tr,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.


            Comment

            • Dooza

              #7
              Re: Remove commas from end of string

              Evertjan. wrote:
              Dooza wrote on 08 jan 2008 in microsoft.publi c.inetserver.as p.general:
              >
              >Evertjan. wrote:
              >>Dooza wrote on 08 jan 2008 in
              >>microsoft.pub lic.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.writ e endCommasAway(s )
              >>%>
              >>>
              >><script language='jscri pt' 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

              Comment

              • Dooza

                #8
                Re: Remove commas from end of string

                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,trims tr)
                > while trim(left(str,1 ))=trimstr
                > str=trim(right( str,Len(str)-1))
                > wend
                > while trim(right(str, 1))=trimstr
                > str=trim(Left(s tr,Len(str)-1))
                > wend
                > ctrim=str
                >end function
                >>
                ><%
                >str=",,a,b,c ,"
                >Response.wri te 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(Ses sion("firstname "),","),"," )

                Steve

                Comment

                • Bob Barrows [MVP]

                  #9
                  Re: Remove commas from end of string

                  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.


                  Comment

                  • Dooza

                    #10
                    Re: Remove commas from end of string

                    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

                    Comment

                    • Evertjan.

                      #11
                      Re: Remove commas from end of string

                      Dooza wrote on 08 jan 2008 in microsoft.publi c.inetserver.as p.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)

                      Comment

                      • Dooza

                        #12
                        Re: Remove commas from end of string

                        Evertjan. wrote:
                        Dooza wrote on 08 jan 2008 in microsoft.publi c.inetserver.as p.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

                        Comment

                        Working...