簡體   English   中英

我如何用所需的字符串替換

[英]How can i replace a string with the required

大家好,我的資料如下

52201               1                   1         PPD1         111017111017   1111000020000003

在這里,我想用0000002替換為bold ,任何人都可以幫助我。 我使用了以下內容,但無法替換

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));
     }                       
  }
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")

 string newS = System.Text.RegularExpressions.Regex.Replace(s, @"\*\*[0-9]+\*\*", "0000002");

但是我不知道你是否想要正則表達式解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM