Thread: Stripping quotes from a string

  1. #1
    Registered User
    Join Date
    Mar 2006

    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 ""

    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 11:27 AM.

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

    You might want to shift the array with memmove().

    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:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

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

    I've got it to work with this piece of 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 ""
    Last edited by -W0kk3L-; 03-15-2006 at 12:29 PM.

  4. #4
    Registered User
    Join Date
    Mar 2006
    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, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM