Question to split by words

Hey,

i have a problem to split a string with strtok.

My String i have to split looks like this:

"|0|H|h[19]|h|r|0|H|h[38]|h|r"

The problem is, that this string isn't alway the same.
I need to replace the numbers with names. For example for
19 = "peter"
38 = "luis"

I had the idea, to set a patern before the numbers, and then split by
the patern. (For example [$19], [$38]).
But i really dont find a way, to do this like i want.

I would realy thanksful if anyone can help me by my problem.

With best regards.
Unfortunately, strtok() is the wrong function to use for this -- it modifies the string (and overwrites part of the number).

It would be simpler to just copy, character-by-character, the string until you encounter a digit.
Once you find the digit, read the number, perform your lookup and copy the name to the destination string. Then continue.

[edit]
Are the numbers always surrounded by square brackets?
What about the zeros in the string?
What if a number isn't found in your lookup table?
Last edited on
Yes, the numbers are always in the square brackets.
What do you mean with zeros?

Later i check the numbers , if it isnt in my lookup table, i return the number (no string).

Topic archived. No new replies allowed.