How to remove minor zeros from a string?

I have the following string values.

00000062178221 00000000054210 00004210555001 

How to clear a line and remove zero pads on the left? I am using C # and .net 2.0. Expected results:

 62178221 54210 4210555001 
+4
source share
2 answers

It should be pretty effective.

 string str = "000001234"; str = str.TrimStart('0'); 
+12
source
 string s = "0001234"; s = s.TrimStart('0'); 

You might want to add

 if (s == "") s = "0"; 

to avoid converting 00000000 to an empty string.

+12
source

Source: https://habr.com/ru/post/1394135/


All Articles