Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CString Find and Substring functions

0 views
Skip to first unread message

Tim Kelley

unread,
Mar 14, 2007, 11:11:24 AM3/14/07
to
I am new to Visual C++ and I am having difficulty parsing a string. We have
a database that has a text field that contains multiple lines (seperated by
a carriage return and new line characters). I retrieve the field into a
CString type variable (just because that is what is used elsewhere in the
program). I need to parse out the lines of the data into 2 or 3 seperate
variables. Am I using the correct data type? If so, what functions can I
use to find and then parse (substring) out the portion of the string I need.

Thanks for your help.


chary

unread,
Mar 14, 2007, 1:39:12 PM3/14/07
to
Hi,

If you want to use CString then you can use the Find method to find
the location of the newline character, and use this location to get
the left or right of the string.

Example:
*/
CString str1 = "This is first line.\nThis is second line.", str2;
str2 = str1.Left(str1.Find("\n"));

//str2 holds only the text "This is first line."

Instead of CString if you go for char pointer/array or string then you
can use the strtok method to parse.


Thanks,
Chary.

0 new messages