I have a string which is beginning with zeros:
string s = "000045zxxcC648700";
How can I remove them so that string will look like:
string s = "45zxxcC648700";
The replaceAll() method of the String class accepts two strings representing a regular expression and a replacement String and replaces the matched values with given String. The ^0+(?! $)"; To remove the leading zeros from a string pass this as first parameter and “” as second parameter.
Basically it performs three steps: Replace each 0 with a space – REPLACE([CustomerKey], '0', ' ') Use the LTRIM string function to trim leading spaces – LTRIM(<Step #1 Result>) Lastly, replace all spaces back to 0 – REPLACE(<Step #2 Result>, ' ', '0')
I would use TrimStart
string no_start_zeros = s.TrimStart('0');
You can use .TrimStart()
like this:
s.TrimStart('0')
Example:
string s = "000045zxxcC648700"; s = s.TrimStart('0'); //s == "45zxxcC648700"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With