Delphi 7
How do i remove leading zeros in a delphi string?
Example:
00000004357816
function removeLeadingZeros(ValueStr: String): String
begin
result:=
end;
Use the inbuilt replaceAll() method of the String class which accepts two parameters, a Regular Expression, and a Replacement String. To remove the leading zeros, pass a Regex as the first parameter and empty string as the second parameter. This method replaces the matched value with the given string.
Approach: Mark the first non-zero number's index in the given array. Store the numbers from that index to the end in a different array. Print the array once all numbers have been stored in a different container.
Searching for this in 2021 there is a much better solution that I found now and that is using the TStringHelper function TrimLeft as follows
myString := myString.TrimLeft(['0']);
see here for more on the documentation http://docwiki.embarcadero.com/Libraries/Sydney/en/System.SysUtils.TStringHelper.TrimLeft
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