查找特定标签并按编号排序

时间:2018-11-10 10:09:14

标签: c#

在找到特定标签(例如BA)中的所有数字后,我想输入一个文本。

FORM_ADS  BA="1" BB="103" BC="000055512100" BD="0" BE="1" BF="13970806" S="11111" BT="1" BU="1" BV="6" BW="0" BX="0" BYY="16" BZ="15721120" CB="0" EB="13388" BAA="13313880" BAB="14793200" BAC="0" BAD="927920" BAE="0" BAF="-3416408"  


FORM_ADS  BA="2" BB="103" BC="000050476860" BD="0" BE="1" BF="13970806"  BS="11111" BT="1" BU="1" BV="6" BW="0" BX="0" BYY="16" BZ="14326424" CB="0" EB="13376" BAA="11238300" BAB="12487000" BAC="0" BAD="1839424" BAE="0" BAF="-3022728"  


FORM_ADS  BA="1" BB="103" BC="001740832930" BD="0" BE="1" BF="13970806" BS="11111" BT="1" BU="1" BV="6" BW="0" BX="0" BYY="16" BZ="18814350" CB="0" EB="13388" BAA="16025580" BAB="17806200" BAC="0" BAD="1008150" BAE="0" BAF="-3034878"    


FORM_ADS  BA="2" BB="103" BC="000050095071" BD="0" BE="1" BF="13970901" BR="0000106933" BS="11111" BT="1" BU="1" BV="6" BW="0" BX="0" BYY="16" BZ="3296900" CB="0" EB="8357" BAA="2967210" BAB="0" BAC="0" BAD="0" BAE="0" BAF="740378"    

1 个答案:

答案 0 :(得分:0)

您可以使用正则表达式捕获任何BA =“#”,然后将其替换为BA =“ {index}”:

// read your text
string allText = Filre.ReadAllText(path);
string format = "BA=\"(.*?)\"";
int index = 1;
allText = Regex.Replace(allText, format, match =>  $"BA=\"{index++}\"");
// now write your text back to file