Reputation: 8636
Hi all i am having my data as follows
52201 1 1 PPD1 111017111017 1111000020000003
Here i would like to replace the one with bold
to 0000002
can any one help me. I used the following but i am unable to replace it
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));
}
}
Upvotes: 0
Views: 91
Reputation: 111860
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 digits is an int
, not a short
!!!
And to format the number back with the padding you can use iBtchno.ToString("d7")
.
Upvotes: 4
Reputation: 148524
string newS = System.Text.RegularExpressions.Regex.Replace(s, @"\*\*[0-9]+\*\*", "0000002");
but i dont know if you want regex solution
Upvotes: 0