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
[149 byte] By [Ray Schmidt] at [2007-11-18 19:27:58]
# 1 Re: Truncate leading 0 in a CString
I thinks these CString's member functions maybe useful : Find() and Remove().

Monch
Monch at 2007-11-11 1:17:05 >
# 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.
cvogt61457 at 2007-11-11 1:18:08 >
# 3 Re: Truncate leading 0 in a CString
CString::TrimLeft('0');
GCDEF at 2007-11-11 1:19:07 >
# 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:
VictorN at 2007-11-11 1:20:09 >
# 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
Ray Schmidt at 2007-11-11 1:21:08 >
# 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:
Ray Schmidt at 2007-11-11 1:22:10 >
# 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 >