CString Find and Substring functions

  • Thread starter Thread starter Tim Kelley
  • Start date Start date
T

Tim Kelley

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.
 
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.
 
Back
Top