strip commas from string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry I Smith

    #16
    Re: strip commas from string

    ineedyourluvin1 @yahoo.com wrote:[color=blue]
    > So what would be the std libs I can link with ? I mean is there a such
    > thing as iostream.lib ? I did a harddrive search and nothing like that
    > was found. I would like to know.[/color]

    [snip]
    [color=blue]
    > Me
    >[/color]

    The Std lib names vary from platform to platform.
    Consult your compiler and Operating System documentation
    for details.

    For example, on my Linux system, the C++ Std lib is:

    libstdc++.so.5. 0.

    and is passed to the linker by 'g++' as '-lstdc++'

    It'll be different on Windows, Solaris, HP-UX, AIX, etc.
    Different libs may be linked based on compiler flags:

    compile multi-threaded yes/no
    compile debug yes/no
    use Network sockets yes/no
    etc, etc, etc

    Ask additional question in the newsgroup(s) associated
    with your compiler and Operating System.

    Regards,
    Larry

    Comment

    • Peter Koch Larsen

      #17
      Re: strip commas from string


      <ineedyourluvin 1@yahoo.com> skrev i en meddelelse
      news:1122741023 .698536.258710@ g43g2000cwa.goo glegroups.com.. .[color=blue]
      >
      > Hello all! I've been looking for a way to strip characters from strings
      > such as a comma. This would be great for using a comma
      > as a delimiter. I show you what I have right now.
      >
      >[/color]

      [snip]
      [color=blue]
      >
      > so as you can see it strips commas and puts a space in its place.
      >
      > Thanks for you help :-)
      >[/color]
      If you want to replace commas with spaces simply do:
      std::string s;

      s.replace(s.beg in(),s.end(),', ',' ');

      if you want ro remove commas use:

      std::string s;

      s.erase(std::re move(s.begin(), s.end(),','),s. end());

      You can use similar code for char* strings.



      /Peter


      Comment

      • ineedyourluvin1@yahoo.com

        #18
        Re: strip commas from string

        Wow that really makes it easy :-) Thanks Peter!

        Comment

        • Ram

          #19
          Re: strip commas from string

          Yes, using std::string functions is the most recommended & convenient
          way. You might find it useful to explore other std::string functions,
          there's one for almost every common task associated with a string.

          Ramashish

          Comment

          • Nikku

            #20
            Re: strip commas from string

            Hello there,

            The following snippet may be useful;


            char s[10];
            ...
            ...
            for (i=0,s[i]=strtok(input," ,");s[i]!=NULL;s[i]=strtok(NULL,", "),i++)
            printf("String i --> %s \n",s[i]);
            ...
            ...

            /Rajesh

            ineedyourluvin1 @yahoo.com wrote:[color=blue]
            > Hello all! I've been looking for a way to strip characters from strings
            > such as a comma. This would be great for using a comma
            > as a delimiter. I show you what I have right now.
            >
            >
            > #include<iostre am>
            > #include<string >
            >
            > int main(int argc, char *argv[])
            > {
            > using namespace std ;
            >
            > char people[14] = "Me,Myself, I" ;
            > char nocommas[14] ;
            > int i, j ;
            > i=j=0 ;
            >
            >
            >
            >
            >
            > for(i = 0; i < 14; i++){
            > if(people[i] != ',')
            > nocommas[i] = people[i] ;
            >
            > if(people[i] == ',')
            > nocommas[i] = ' ' ;
            > }
            >
            >
            >
            > cout << "With commas : " << people << endl ;
            > cout << "Without commas : " << nocommas << endl ;
            >
            > cout << "\n\n\n\n" ;
            > cout << "\tNow tell me how I can store each name in a separate
            > variable ?" << endl ;
            > cout << "\tAnd can someone show me how to do this with string instead
            > of char[] ?" << endl ;
            > cout << "\t\t Thanks so much!" << endl ;
            >
            > return 0 ;
            > }
            >
            >
            > so as you can see it strips commas and puts a space in its place.
            >
            > Thanks for you help :-)[/color]

            Comment

            • SUNROCKET

              #21
              SUNROCKET FREE PHONES HERE

              SUNROCKET FREE PHONES HERE
              SunRocket Promotion Free Phones!
              Far better is it to dare mighty things, to win glorius triumphs, even though checkered by failure... than to rank with those poor spirits who neither enjoy nor suffer much, because they live in a gray twilight that knows not victory nor defeat. Theodore Roosevelt

              [b:adb10dde8a][color=red:adb10 dde8a]SUNROCKET BLOG
              Recieve two FREE Uniden Cordless
              phones[/color:adb10dde8 a][/b:adb10dde8a]




              Sent via Archivaty.com

              Comment

              • SUNROCKET

                #22
                SUNROCKET

                SUNROCKET FREE PHONES HERE
                SunRocket Promotion Free Phones!
                Far better is it to dare mighty things, to win glorius triumphs, even though checkered by failure... than to rank with those poor spirits who neither enjoy nor suffer much, because they live in a gray twilight that knows not victory nor defeat. Theodore Roosevelt

                [b:0a2b1f0e20][color=red:0a2b1 f0e20]SUNROCKET BLOG
                Recieve two FREE Uniden Cordless
                phones[/color:0a2b1f0e2 0][/b:0a2b1f0e20]




                Sent via Archivaty.com

                Comment

                • Peter_Julian

                  #23
                  Re: SUNROCKET


                  "SUNROCKET" <REDROCKET@MAIL INATOR-dot-COM.no-spam.invalid> wrote in
                  message news:1NKdnVnMF_ T2LuPenZ2dnUVZ_ sqdnZ2d@giganew s.com...

                  <snip>

                  for the record: abuse@giganews. com
                  and a full header + message was sent.

                  We don't need total idiots here. Specially an idiot that configures the
                  newsreader to only show unread messages. If you composed it, you've read
                  it, duh!


                  Comment

                  Working...