Parsing a string that contains only one seperator
-
I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva
-
I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva
The C way would be with strtok, but otherwise, you'd use CString::Find, which allows you to find the first instance of a substring starting from a specified position, and CString::Mid which allows you to pull a substring out of the middle. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
-
I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva
try this: :) CString text = "Jake#Caroline#Mark#Anthony#Sid#"; CString name; int index=0; while (AfxExtractSubString(name, text, index++, '#') { if (name != "") { // do something } }
-
I have a CString. It contains multiple #'s that break it up. Now i want to get each piece of text seperately between the #'s. For example: Jake#Caroline#Mark#Anthony#Sid# The string ends with # but doesn't start with # (although you can presume otherwise because it can be changed). Hows the easy way to do this? (preferably the MFC CString way ;) ) Thanks P.S.: i'll stop hasssling u ppl now lolz, i'm working on a program thats why i was asking so many questions hehe. Kuniva
One way to do is to copy the CString to a char buffer and strtok() your way through the buffer. (Btw, if you're using the CP forums to get canned answers to your schoolwork, you're only hurting yourself.) /ravi "There is always one more bug..." http://www.ravib.com raviv@ravib.com
-
One way to do is to copy the CString to a char buffer and strtok() your way through the buffer. (Btw, if you're using the CP forums to get canned answers to your schoolwork, you're only hurting yourself.) /ravi "There is always one more bug..." http://www.ravib.com raviv@ravib.com
-
One way to do is to copy the CString to a char buffer and strtok() your way through the buffer. (Btw, if you're using the CP forums to get canned answers to your schoolwork, you're only hurting yourself.) /ravi "There is always one more bug..." http://www.ravib.com raviv@ravib.com
-
Can you tell me how I copy a string to a char buffer? Sorry if this question is a bit stupid...
Stevieslu wrote: Sorry if this question is a bit stupid... The only stupid question is the one not asked! Here's how:
char szBuffer [LARGE_ENOUGH_TO_HOLD_STRING];
CString strMyString = "Whatever";szBuffer [0] = '\0';
if (strMyString.GetLength() < LARGE_ENOUGH_TO_HOLD_STRING) {
strcpy (szBuffer, strMyString.GetBuffer (0));
strMyString.ReleaseBuffer();
}/ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com