Wednesday, March 24, 2010

How to truncate leading zeros from a String?

The common functionality a .Net developers uses is to extracting integer/numeric value from a string having leading ZEROS.

Suppose we have a a string "00025" and we want to get only 25 of it.

Example:
Int32 intOutValue;
bool blnParsed;
String strNumber = "00025";

blnParsed= Int32.TryParse(strNumber , out intOutValue);

Output:
blnParsed=true
intOutValue = 25

No comments:

Post a Comment