I need your help on this guys...
-
Hi, I actually have 3 ?s: 1- How can I convert a CString to a c-char (char[25]) and vice-versa. 2- How can I convert a CString to a int, fl int or other number holder. 3- How can I extract a certain portion of a CString, like the first 2 chars for example. // JS Paquet cout << "Thank you all" << endl;
-
Hi, I actually have 3 ?s: 1- How can I convert a CString to a c-char (char[25]) and vice-versa. 2- How can I convert a CString to a int, fl int or other number holder. 3- How can I extract a certain portion of a CString, like the first 2 chars for example. // JS Paquet cout << "Thank you all" << endl;
- If you don't need to modify the char array, you can simply cast a CString to an LPCTSTR (long? pointer const TCHAR string):
LPCTSTR apszBuffer = (LPCTSTR)m_MyCstring;
If you need to modify the buffer, you need to use GetBuffer and ReleaseBuffer:
LPTSTR apszMyBuffer = m_MyCString.GetBuffer(m_MyCString.GetLength());
// Do something with apszMyBuffer, changing its length to 25
m_MyCString.ReleaseBuffer(25);- Use atoi, atof (or _ttoi for wide-char compatibility):
int viValue = atoi("25478");
float vfValue = atof("123.456");- Use CString::Mid():
CString vstrBit = m_MyCString.Mid(0, 2); // First two chars
CString vstrAnother = m_MyCString.Mid(5, 4); // Chars 5-8Hope this helps. ------------------------ Derek Waters derek@lj-oz.com