大家好我所拥有的数据如下
52201 1 1 PPD1 111017111017 1111000020000003
在这里,我想将bold
替换为0000002
,任何人都可以帮助我。我使用了以下但我无法替换它
if (strBtchno1.StartsWith("5"))
{
iBtchno = Convert.ToInt16(strBtchno1.Substring(87, 7));
if (iBtchno > iBatchno)
{
iBtchno = iBtchno - 1;
strBtchno1 = strBtchno1.Substring(0,87) + iBtchno.ToString() + strBtchno1.Substring(7,(strBtchno1.Length - 7));
}
}
答案 0 :(得分:4)
string strBtchno1 = "52201 1 1 PPD1 111017111017 1111000020000003";
int iBtchno = Convert.ToInt32(strBtchno1.Substring(strBtchno1.Length - 7));
iBtchno++;
strBtchno1 = strBtchno1.Substring(0, strBtchno1.Length - 7) + iBtchno.ToString("d7");
7位数是int
,而不是short
!!!
要使用填充格式将数字格式化,您可以使用iBtchno.ToString("d7")
。
答案 1 :(得分:0)
string newS = System.Text.RegularExpressions.Regex.Replace(s, @"\*\*[0-9]+\*\*", "0000002");
但我不知道你是否想要正则表达式解决方案