我想在字符串中用零(必须是8位数字)填充每个数字
e、 g
asd 123 rete>;asd 00000123 rete
4444我的文本>;00004444我的文本
是否可以使用正则表达式来实现这一点?尤其是Regex.Replace()
请注意,对于不同的数字,零的数量是不同的。我的意思是填充的数字必须是8位数
Microsoft为此内置了以下功能:
someString=someString.PadLeft(8,'0');
这里有一篇关于MSDN的文章
要使用正则表达式,请执行以下操作:
string someText=“asd 123 rete”;
someText=Regex.Replace(someText,@“\d+”,n=>;n.Value.PadLeft(8,'0'));