Reputation: 312
I'm using strtok
in the hope of doing something like Php's explode
.
At first I thought the following was working correctly
details = strtok(line,"]:");
But after some closer inspection I realised it was using any instance of ]
and :
to split the string. What I need is for it to only split the string where the two are together - ]:
.
Maybe strtok
is the wrong function for this? I played around with str_split
but this didn't work, either through my implementation or unsuitability.
Any help welcome on splitting my string where an occurrence of ]:
is found.
Upvotes: 0
Views: 82
Reputation: 11628
In C "splitting" a string is really a matter of inserting a null terminator (0x00) in the string itself and let a new char* point to the next byte after it.
It's not so obvious how to do it and, more important, there are many ways to do it
Upvotes: 1
Reputation: 78573
strtok is the wrong function to use as it will split on any of the characters in the set of delimiters.
I'm not aware of any standard function to do what you want. You might have to roll your own.
Upvotes: 1