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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CString converstion

Status
Not open for further replies.

SteveD73

Programmer
Jan 5, 2001
109
0
0
GB
Hello

I have a CString like the following:

szTest = "673845"

I need to break it down into three variables like so:

int x = 67;
int y = 38;
int z = 45;

Does anyone know how to do this?

Thanks
 
Well there are different ways you can do this, here is one.

int x = szText.Mid(0,2);
int y = szText.Mid(2,2);
int z = szText.Mid(4);

Good luck
-pete
 
I think strings need to be converted into numerical values

int x = atoi(szText.Mid(0,2));
int y = atoi(szText.Mid(2,2));
int z = atoi(szText.Mid(4));

incase of Unicode Strings better use mfc Macro's

int x = atoi(W2A(szText.Mid(0,2)));
int y = atoi(W2A(szText.Mid(2,2)));
int z = atoi(W2A(szText.Mid(4)));
 
sanjay123 you've made me the happiest programmer on this planet!

i've been searching for over 7 hours for a function to convert strings to ints THANKS A BUNCH

later...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top