String tokenizer and delimiters

This is a discussion on String tokenizer and delimiters within the C Programming forums, part of the General Programming Boards category; I've filtered almost every delimiter I could think of when processing text files. I'm curious if it's possible to filter ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    119

    String tokenizer and delimiters

    I've filtered almost every delimiter I could think of when processing text files. I'm curious if it's possible to filter out quotation marks " " in the delimiter string that I pass to the strtok function. It would be a lot simpler than stripping them out of the string before storing it. It doesn't really work if you enter a single quotation mark because it closes the initial quotation mark for the delimiter string.

    char *delim = " .<>!/:" => another quotation mark will just screw it up

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I'm curious if it's possible to filter out quotation marks " " in the delimiter string that I pass to the strtok function.
    Sure anytime you need to add a quotation mark to a string, just escape it first with a backslash (similar to adding a newline):
    Code:
    char *delim = "\"";

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by John_L View Post
    char *delim = " .<>!/:" => another quotation mark will just screw it up
    Never heard of an escape?

    Code:
    char *delim = ".<>!/:\"";

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    119
    no i havn't, but thanks for the tip

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by John_L View Post
    no i havn't, but thanks for the tip
    Yep. You can put a " character in a string by preceding it with a backslash.

  6. #6
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    the delimiter string that I pass to the strtok function
    And make sure that get the backup of the original string before u send it strtok. Since Strtok damage the string. I mean u won't get original string back. If you need that for future reference in the code.

    ssharish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. return character arrays
    By Azmeos in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2003, 07:15 AM

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