Truncate leading 0 in a CString
:rolleyes: If I have input taken from a CString, is there a way to ignore or truncate leading '0' in it?
Thanks,
Ray Schmidt
# 2 Re: Truncate leading 0 in a CString
The way that a string works is that there are only ASCII characters
in the body of the string followed by a terminating null.
CString also uses this convention.
Having a null inside the body of the string is not supported well.
You can force one in. But the CString won't handle it well in all
circumstances.
Try using a CByteArray instead.
# 4 Re: Truncate leading 0 in a CString
hi, cvogt61457!
Having a null inside the body of the string is not supported well. Yes! it is correct.
However, Ray Schmidt meant '0' character, not a Nul! :wave:
# 5 Re: Truncate leading 0 in a CString
Thanks for all the comments!!! It's nice to get the help one needs... What I have is a numeric locked edit box only allowing numbers into a CString (or CByteArray which I have not looked up yet). If in the event a number like 00608 were entered, I would only want the 608 to be valid. It looks like I might be able to explore the use of CString::TrimLeft('0'); if it works like what I need above. Any other suggestions are appreciated!!!
Thanks,
Ray Schmidt
# 6 Re: Truncate leading 0 in a CString
It seems like this will do the trick!!!
m_truncated = atof(m_totruncate);
Converting it to a numeric value and then pass back to CString...
Ray :thumb:
# 7 Re: Truncate leading 0 in a CString
It seems like this will do the trick!!!
m_truncated = atof(m_totruncate);
Converting it to a numeric value and then pass back to CString...
Ray :thumb:
But because it is an integer, you may want to look at using atoi instead?
Mike B
MikeB at 2007-11-11 1:23:14 >
