Hi,
I want to make a CString to for example an Ascii-Code (it should be numbers),
a friend told me, that I should use atoi/atof. How must I use this??
I thanks for every Help!!
Black Racer
Printable View
Hi,
I want to make a CString to for example an Ascii-Code (it should be numbers),
a friend told me, that I should use atoi/atof. How must I use this??
I thanks for every Help!!
Black Racer
No... That's if you have an integer representation in a char string which you want to convert to its numerical equivalent... What you're looking for is _toascii which takes a char at a time, so you'd have to use CString::GetAt() and pass each character in your CString one at a time to _toascii() to get your string equivalent in ASCII.
Rail
Recording Engineer/Software Developer
Rail Jon Rogut Software
[email protected]
http://home.earthlink.net/~railro/
can you show me an short eample??
I have the Name "Black Racer" there, and I would create an SerialNumber.
So I work with the name:
CxyzDlg::ONClick()
{
CString serial1, serial2, serial3, serial4, serial5;
serial1 = m_nameedit; //m_nameedit is the text in TextBox1
serial1.TrimRight(); //you know
serial2 = serial1.Mid(2, 2);
serial3 = serial1.Left(3);
serial4 = serial1.Right(1);
serial5 = serial2 + serial3 + serial4;
if(m_serialedit == serial5)
{
MessageBox("Right Code", MB_OK + MB_ICONINFORMATION);
}
else
{
MessageBox("Wrong Code", MB_OK + MB_ICONINFORMATION);
}
}
So, the problem is, that Serial5 should be a number.
How can I do that???
Black Racer
Here is a function that does exactly what you asked:
double str2float(CString str)
{
CString strFloat = str;
CString strInt = "";
CString strZecim = "0";
BOOL bZecim = FALSE;
for(int c=0; c<strFloat.GetLength(); c++){
if(strFloat[c] == ',' && !bZecim){
bZecim = TRUE;
strZecim = "";
}
if(!bZecim){
if(strFloat[c] >= '0' && strFloat[c] <= '9')
strInt += strFloat[c];
}
else{
if(strFloat[c] >= '0' && strFloat[c] <= '9')
strZecim += strFloat[c];
}
}
strFloat = strInt + "." + strZecim;
return (double)atof(strFloat);
}
Regards,
Dani Zilcsak
mailto:[email protected]