从字符串start c#中删除特定字符

Mig*_*uel -3 c# regex

我想知道如何使用c#中的正则表达式从字符串中删除字符0,以便接收输入:

000004000 after the regex i get: 4000
W050 after the regex i get: W050
Run Code Online (Sandbox Code Playgroud)

我很感激你的帮助.

最好的祝福.

L-F*_*our 8

为什么要使用正则表达式?只需使用TrimStart并保持简单.至少,您的代码是可读的:

 var str = "000004000";
 var trimmedResult  =  str.TrimStart('0');
Run Code Online (Sandbox Code Playgroud)

输出:"4000"