读取 txt 文件内容,内容格式如下
标题|<title>|</title>
内容|<content>|</content>
标题|<title>|</title>
内容|<div class="main-text">|</div>
当读到最后 "内容|<div class="main-text">|</div>" 这行内容的时候自动分成了两行, 而前面的 内容|<content>|</content> 读取正常
使用 StreamReader 读的也是一样
读取行代码段====================================
[C#] 纯文本查看 复制代码 string[] str = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "\\Regex.txt", Encoding.Default);
if (str.Length > 0)
{
for (int i = 0; i < str.Length; i++)
{
string temStr = str[i];
if (temStr.Contains("|"))
{
string[] strStr = temStr.Split('|');
ListViewItem item = new ListViewItem(strStr[0]);
item.SubItems.Add(strStr[1]);
item.SubItems.Add(strStr[2]);
lvRegexList.Items.Add(item);
}
}
}
下面是保存的代码 =================================
[C#] 纯文本查看 复制代码 FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\Regex.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
for (int i = 0; i < lvRegexList.Items.Count; i++)
{
string rTag = lvRegexList.Items[i].SubItems[0].Text;
string rFrist = lvRegexList.Items[i].SubItems[1].Text;
string rTial = lvRegexList.Items[i].SubItems[2].Text;
//File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory+"\\Regex.txt",rTag+"|"+rFrist+"|"+rTial+"\r\n",Encoding.Default);
//File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\Regex.txt", rTag + "|" + rFrist + "|" + rTial + "\r\n", Encoding.Default);
sw.WriteLine(rTag + "|" + rFrist + "|" + rTial);
}
sw.Close();
fs.Close();
|