1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Help Parsing a Pipe Delimited String.

Discussion in 'C' started by wgre0111, Jan 25, 2010.

  1. wgre0111

    wgre0111 New Member

    Joined:
    Oct 19, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Greetings,

    Having issue storing the 3rd value in a pipe delimited string. dont care about the rest of the text... just want to choose the field i want and ignore rest. I hear strtok has some limitations where it would skip a field if it was blank... Dont want to have that possibility. Please Help!

    Example: values = "1||3|NEED|4|5|"

    I want to be able to parse out only the field after the 3rd pipe and store that field in a variable (OR after whatever pipe i choose)
     
  2. kiddo

    kiddo New Member

    Joined:
    Apr 11, 2009
    Messages:
    65
    Likes Received:
    1
    Trophy Points:
    0
    Can you explain more about the problem?
    I don't get the point.

    Maybe another example..
     
  3. wgre0111

    wgre0111 New Member

    Joined:
    Oct 19, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Lets see..

    I have a variable that has the following information "1||3|4|NEED|5|hrrm|ok"

    I need code to be able to choose WHICH ever field i want. like i want to be able able to say I want field 5 and have it return only the word NEED into output or into another variable.

    strtok has its limitations because it will get tripped up over the blank field "||"

    I know how to do this other ways but they require me to loop thru and use a counter to stop on the occurrence.

    Just trying to avoid that with some type of scanf or anything that wont get tripped up over blank fields.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What's wrong with that? (It's what I'd do.)
     

Share This Page