|
-
April 27th, 2004, 04:58 PM
#1
Get Substring
I do have a string given to me as
CString strString = "ON,IN,1,0 ms";
I want to separate the string to another string where I have to look for the comma
I want the other string to be something like
CString strString2[4]
where
strString2[0] = "ON"
strString2[1] = "IN"
strString2[2] = "1"
strString2[3] = "0ms"
I want to know what function should I use to split that string on the form above.
-
April 27th, 2004, 05:18 PM
#2
RE: Get substring
Originally quoted by vcstarter
I want to separate the string to another string where I have to look for the comma
If you have VC.net which uses the "new" CSimpleStringT you can use Tokenize which works like the old strtok. Otherwise you can do it with CString::Find, CString::Mid and a while loop.
TDM
-
April 27th, 2004, 06:26 PM
#3
One little function for that would be:
void ChopString(CString& src,const char seperator,CStringArray& ary)
{
int index=0;
CString leftover,temp;
do
{
index=src.Find(seperator);
leftover=src.Mid(index+1,src.GetLength()-index-1);
if(index!=-1) temp=src.Left(index);
else
temp=src;
ary.Add(temp);
src=leftover;
}while(index!=-1);
}
-
April 28th, 2004, 02:42 AM
#4
There is a function that does whatever you want to get substrings.
It is called AfxExtractSubstring. It is not well documented, but if you type it in VC++ editor you will see its parameters.
Caronte
Si tiene solución... ¿por qué te preocupas?
Si no tiene solución... ¿por qué te preocupas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|