[英]How to add space two positions after each comma in string
我有一个像这样的字符串:
st = 0,090,000,170,16-0,030,19 0,330,19
如何在其中添加一个空格,每个逗号后两个位置,以获得如下字符串:
st = 0,09 0,00 0,17 0,16 -0,03 0,19 0,33 0,19
使用 Regex.Replace 如下
var oldString = "0,090,000,170,16 - 0,030,19 0,330,19";
var newString = Regex.Replace(oldString, ",[0-9]{2}", (match) => { return match.Value + " "; });
string st = "0,090,000,170,16-0,030,19 0,330,19", aux = "";
int offset = 2;
for (int npos = 0; npos < st.Length; ++npos)
{
aux += st[npos];
if (st[npos] == ',')
{
for (int mpos = 1; mpos <= offset; ++mpos)
aux += st[npos + mpos];
aux += ' ';
npos += offset;
}
}
st = aux;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.