嗨,我正在学习 C#,我有一些 .inf 文件(请参见下面的示例),我需要能够更改 [Destinations] 部分,其中一行以“00”或“0”开头并带有“+”。我曾尝试使用 Regex.Replace,但它会替换文件中包含“00”的所有条目。在这一点上,将两个条目都保留在文件中会很好但不是必需的。IE
[Destinations]
0="National",N,N
+="National",N,N
0024195="Gabon Mobiles",I,IMT
+24195="Gabon Mobiles",I,IMT
但现在只是更换将是一个巨大的帮助!再次感谢您对此提供的任何帮助。如果您有更多信息,请告诉我。
[Carrier]
Name=BT Customer Commitment
ChargeStructure=1 Year 50K
[ChargeBands]
Loc=Local Rate Calls
Nat=National Rate Calls
dq1=Directory Enquiries
dq2=Directory Enquiries
dq3=Directory Enquiries
dq4=Directory Enquiries
dq5=Directory Enquiries
[ChargeRates]
Loc,E="Economy",0,1000,60000,990,2800,Nearest,100
Loc,S="Standard",0,1000,60000,2450,2800,Nearest,100
Loc,W="Weekend",0,1000,60000,690,2800,Nearest,100
Nat,E="Economy",0,1000,60000,3190,2800,Nearest,100
Nat,S="Standard",0,1000,60000,6390,2800,Nearest,100
[DailyRates]
Loc,0=0000:E,0800:S,1800:E
Loc,1=0000:E,0800:S,1800:E
Loc,2=0000:E,0800:S,1800:E
Loc,3=0000:E,0800:S,1800:E
Loc,4=0000:E,0800:S,1800:E
[Destinations]
0="National",N,N
00="International",I,IV
0024195="Gabon Mobiles",I,IMT
0024197="Gabon Mobiles",I,IMT
00242="Congo",I,IS
090610="Premium Rate",M,n
0906100="C & W Premium Rate",M,n
这是我对 C# 代码所做的。
private void button3_Click(object sender, EventArgs e)
{
File.WriteAllText(txtnewtariff.Text, Regex.Replace(File.ReadAllText(txtcurrent.Text), "[00]", "+"));
}