【发布时间】:2014-11-20 23:59:12
【问题描述】:
我正在根据我的 .ini 文件删除一些名称。我的 .ini 文件 中列出了一些名称。每次我的应用程序处理输入文件时,它都会从 .ini 文件中查找某些关键字,如果在我的输入文件中找到该关键字,它会删除整行。
但对我来说,发生的事情是当 .ini 文件在我的文本文件中找到关键搜索 && 如果我的关键搜索在我的第二列中,那么它只会删除该行。我希望关键字搜索也在我的文本文件中查找我的第一列。这个怎么加??
代码sn-p:
public void do_name()
{
string old;
string iniPath = Application.StartupPath + "\\list.ini";
bool isDeleteSectionFound = false;
List<string> deleteCodeList = new List<string>();
using (StreamReader sr = File.OpenText(iniPath))
{
while ((old = sr.ReadLine()) != null)
{
if (old.Trim().Equals("[DELETE]"))
{
isDeleteSectionFound = true;
}
if (isDeleteSectionFound && !old.Trim().Equals("[DELETE]"))
{
deleteCodeList.Add(old.Trim());
}
}
}
StringBuilder sb = new StringBuilder();
using (StreamReader sr = File.OpenText(textBox1.Text))
{
while ((old = sr.ReadLine()) != null)
{
var st = old.Trim().Split(new char[] { '\t' });
if (st.Length > 1)
{
var tempCode = st[1].Substring(1, st[1].Length - 2);
if (!deleteCodeList.Contains(tempCode))
{
sb.AppendLine(old);
}
}
else if (st.Length == 1)
{
//old = "\n";
sb.AppendLine(old);
}
}
}
File.WriteAllText(textBox1.Text, sb.ToString());
}
我的输入文本文件:在这里你可以看到,第一列的值由于某些原因没有被搜索到。不知道。。
Designator MAX PN Footprint Center-X(mm) Center-Y(mm)
"C10" "100-0009" "1206 - CAPACITOR" "122.492" "69.469"
"C100" "100-0009" "1206 - CAPACITOR" "264.211" "12.814"
"C102" "100-0009" "1206 - CAPACITOR" "251.346" "11.201"
I would like to add C10, C100 and all first column elements to my .ini file
我的 .ini 文件看起来像
[DELETE]
100-2333
233-3233
C10
【问题讨论】:
标签: c# string visual-studio-2010 text ini