0

I have a CString :

CString data;
data.Format = ("!64.8 Px.1= 1200");

I would like to copy the number 1200 from data to another CString data2.

Anyone can help?

Thanks in advance

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by mitrmkar
0

CString::Format() works like sprintf() , so you can do ..

CString data; 
CString data2 = _T("1200");

data.Format(_T("!64.8 Px.1= %s"), (LPCTSTR)data2);
0

CString::Format() works like sprintf() , so you can do ..

CString data; 
CString data2 = _T("1200");

data.Format(_T("!64.8 Px.1= %s"), (LPCTSTR)data2);

For my application, the number 1200 from data string keep changing. I would like to copy the number out from data to another CString data2 so that i can prinf the number from data2 instead of the whole string of data.

data.Format(_T("!64.8 Px.1= 1200")); // 1200 keep changing
//Copy the number 1200 from data to data2

printf("%s", data2); //prinf the number instead of whole string

Is there a way to just copy the number from CString data to CString data2?

Thank you.

0

How about by-passing the CString here, and printf() 'ing the number directly, so,

// Somewhere you probably have ..
int the_number;
// .. and then output it ..
printf("!64.8 Px.1= %d", the_number);

If that's not an option, then you have to parse the data string to get the number.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.