anybody knows if theres any function to split a string by a character.. for example i have:
MessageŽMessageŽMessageŽMessageŽMessageŽMessageŽ.. ..
and i want to split all by the Ž character and just get "Message" in arrays of CString
thanks
anybody knows if theres any function to split a string by a character.. for example i have:
MessageŽMessageŽMessageŽMessageŽMessageŽMessageŽ.. ..
and i want to split all by the Ž character and just get "Message" in arrays of CString
thanks
What you are looking for is to separate a string into tokens. This can be accomplished in C using strtok(). Here is the FAQ on strtok . And below is a sample program that seperates user input into tokens based on " "(spaces).
And here is my output:Code:#include <stdio.h> #include <string.h> int main(void) { int j, i=0; // used to iterate through array char userInput[81], *token[80]; //user input and array to hold max possible tokens, aka 80. printf("Enter a line of text to be tokenized: "); fgets(userInput, sizeof(userInput), stdin); token[0] = strtok(userInput, " "); //get pointer to first token found and store in 0 //place in array while(token[i]!= NULL) { //ensure a pointer was found i++; token[i] = strtok(NULL, " "); //continue to tokenize the string } for(j = 0; j <= i-1; j++) { printf("%s\n", token[j]); //print out all of the tokens } return 0; }
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
hmm was thinking if there is another function in mfc for strings like there is in visual basic :P Split(start number,"string","separator",max splitings)
anyway thanks i think i have to make my own function for that