Stripping quotes from a string

This is a discussion on Stripping quotes from a string within the C Programming forums, part of the General Programming Boards category; Hi all, Maybe someone can help me with this problem. I'm trying to replace two following quotes in a string ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Stripping quotes from a string

    Hi all,

    Maybe someone can help me with this problem. I'm trying to replace two following quotes in a string to one quote. For example:

    L 03/15/2006 - 18:17:17: Rcon: "rcon 1033369585 "password" kick "blabla bla bla"" from "123.123.123.123:1234"

    I'm currently using strtok at the quotes to split the complete string in pieces, which i place in an array. Most of the time there are no double sets of quotes (like shown in bold in the example), but sometimes they pop up because someone uses quotes in a rcon command on our gameservers.

    This is when the problem occures. Because i split on the quotes, the array gets shifted, and i get the wrong info when i use that array.

    Is there a way to replace the "" with " so i can use the normal array again? I've tried searching for a good replacement function, but they are hard to find. Even when there are lots of topics about it. Can anyone help me fix this problem?

    It's probably easy for the experts here, but i'm very new in C
    Last edited by -W0kk3L-; 03-15-2006 at 10:27 AM.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Use strstr() to find "", and shift the array to the left.

    [edit]
    You might want to shift the array with memmove().
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Hmm, good suggestion!

    I've got it to work with this piece of code code:

    Code:
       ptr = strstr(my_input_string,"\"\"");
       if(ptr != 0)
       {
          len = strlen(ptr+2);
          // the string exists
          memmove(ptr, ptr+1,strlen(ptr+1));
          // now null-terminate the string
          ptr[len] = 0;
       }
    But i already ran into the next problem which i overlooked. Is it also possible to remove the quote prior to the one i found? Is there a way to reverse-search (and destroy! ) the previous quote, when i find a double quote like above?

    I mean the bold char:
    log L 03/15/2006 - 19:05:51: Rcon: "rcon 1033369585 "password" kick "blabla bla bla" from "123.123.123.123:1234"
    Last edited by -W0kk3L-; 03-15-2006 at 11:29 AM.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Never mind!.. fix it in a different way, by counting the number of string in the array and changing the output. Thnx for your help dwks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21