How to tokenize the string
-
I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".
-
I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".
you have to get the # character from the string, and test its following character. i'm about to post an article about something like that (parsing streams)... wait a bit ;) (posted) here is a like on parsing code : Visual Calc - A new dimension for the desktop calculator[^]
char ch = str[NextChar++]; // Be careful to test if the index is not out of bounds...
switch (ch) {
case '#':
{
char nch = str[NextChar++];
if (nch == '#') {
// Do some action when ## is found on the stream...
}
else {
// Only one # was found...
NextChar--;
}
break;
}
default:
// Fisrt character is not #...
}
TOXCCT >>> GEII power
-
I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".
Perhaps its wiser to choose a different form of formatting your strings. Why use '##' and '#', they already cause problems trying to distinguish them during parsing. How about using '$' and '%' or something like that. '##' and '#' clearly mean different things to you, so why use such similar signs? Er zit een korstje op mijn aars.
-
I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".
-
I got string like this :"Rassul##Rasul#Yunussov"; And i want to tokenize it to strings : "Rassul" and "Rassul#Yunussov". I know the function strtok - but it doesnt distinguish "##" from "#".
How about:
char *str = "Rassul##Rasul#Yunussov";
char *pos = strstr(str, "##");
char left[16], right[16];
strncpy(left, str, pos - str);
strcpy(right, pos + 2);
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen