Help Parsing a Pipe Delimited String.

wgre0111's Avatar, Join Date: Oct 2008
Light Poster
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)
0
kiddo's Avatar, Join Date: Apr 2009
Contributor
Can you explain more about the problem?
I don't get the point.

Maybe another example..
0
wgre0111's Avatar, Join Date: Oct 2008
Light Poster
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.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Quote:
Originally Posted by wgre0111 View Post
I know how to do this other ways but they require me to loop thru and use a counter to stop on the occurrence.
What's wrong with that? (It's what I'd do.)