Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to extract a string from the statement

Status
Not open for further replies.

MindCracker

Programmer
Aug 27, 2002
21
0
0
GB
if i have a string as:

"Time Decimal(3)"
"Cat Integer "

I want the program each time to extract the second word of the statements. In this case is "Decimal" or "Integer" depending which line has been selected. How am I supposed to do that?

Please help. Many thanks!

 
Try with this function

Works as follows:
CString sResult=GetSecondString("hello world");
(in this case sResult="world")

//THE CODE:
CString& GetSecondString(CString& Data)
{
bool bFound=false;
CString sTempData="";
for(int i=0;i<Data.GetLenght();i++)
{
if(Data.mid(i,1)==&quot; &quot;)
{
if(bFound)
break;
else
bFound=true;
}
else
{
if(bFound)
sTempData+=Data.mid(i,1);
}
return sTempData;
}

HOPE TO HELP YOU!!
Daniel
 
going back to standard C++, you can use the strtok() or strsep() routines. If you don't have the MSDN Library,
look at for an example.
This work on standard null-terminated C-style strings (char *), so if you're using CString, you will need to make a copy of the data first into a modifyable string.

Regards,
Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top