How can i check the String letters?

  • Thread starter Thread starter NEMA
  • Start date Start date
N

NEMA

How can i check the String letters?
i have a textbox and will filled with numbers.
i want to check if the number contain a '0' in font of the numbers,
e.g. '090',i would like to cut the 1st '0', that will change to '90'.
and i want to check whether it has a space there and return an error
message. e.g. '0 9 0', then it will return an error.

i really dont know how to do it? please give me some guidliance,
thanks.
 
Hi,
i would like to cut the 1st '0'
You can try CString::TrimLeft
e.g. CString str = _T ("090");
str = str.Trimeft (_T ('0'));
Note: it will not erase only the first '0', it will trim all leading '0's.
e.g. CString str = _T ("00090");
i want to check whether it has a space there and return an error message. e.g. '0 9 0', then it will return an error
try CString::Find
e.g. CString str = _T ("0 9 0");
//trim leading '0'
str = str.Trimeft (_T ('0'));

//Search space
if( str.Find (_T (' ')) != -1 )
{
//found space, do what you want
}


Yours,
Michael
 
NEMA said:
How can i check the String letters?
i have a textbox and will filled with numbers.
i want to check if the number contain a '0' in font of the numbers,
e.g. '090',i would like to cut the 1st '0', that will change to '90'.
and i want to check whether it has a space there and return an error
message. e.g. '0 9 0', then it will return an error.

Sounds like you want to normalize a integer's string representation. Try
using Integer.TryParse to find out if it's a valid number (will catch spaces
or any other non-digit characters), and then ToString on the result to
format it the way you like, with/without leading zeros, etc.
 
Back
Top