110,499
社区成员
发帖
与我相关
我的任务
分享
static void ParseTxt()
{
/*
* a.txt 数据
* 操作系统确定程序是否成功执行完毕
* 函数体函数定义的最后部分
* 程序编写完后需要进行编译
* 标准库定义了 4 个 IO 对象
* 系统将这些对象与执行程序的窗口联系起来
* 编译器要使用库
*
* b.txt 数据
* 讲解
* 函数部分
* 程序编译
* 标准库对象
* 系统窗口
* 编译器讲解
*
* 解析后新生成的newa.txt应该是这样的
* 操作系统确定程序是否成功执行完毕 【未找到】
* 函数体函数定义的最后部分 体函数定义的最后部分
* 程序编写完后需要进行编译 编写完后需要进行编译
* 标准库定义了 4 个 IO 对象 定义了 4 个 IO 对象
* 系统将这些对象与执行程序的窗口联系起来 将这些对象与执行程序的窗口联系起来
* 编译器要使用库 要使用库
*/
string aPath = "a.txt";//16W+数据
string bPath = "b.txt";//2000+数据
string newaPath = "newa.txt";//与a.txt数据量相同
string[] arrA = File.ReadAllLines(aPath);
string[] arrB = File.ReadAllLines(bPath);
StringBuilder sb = new StringBuilder();
bool isHave = false;
string titleTrim = string.Empty;
string subTitle = string.Empty;
char[] sChar = new char[] { ' ', '[', '[', '(', '『', '(', '{', '【' };
char[] eChar = new char[] { ' ', ']', '+', '/', '』', ']', ')', '-', '}', '】' };
foreach (string title in arrA)
{
titleTrim = title.TrimStart(sChar);
for (int i = 2; i < titleTrim.Length; i++)
{
isHave = false;
subTitle = titleTrim.Substring(0, i);
foreach (string b in arrB)
{
if (b.Contains(subTitle))
{
isHave = true;
break;
}
}
if (!isHave)
{
if (i == 2)
{
sb.Append(title + "\t【未找到】\r\n");
}
else
{
sb.Append(title + "\t" + titleTrim.Substring(i - 1, titleTrim.Length - i + 1).TrimStart(eChar) + "\r\n");
}
break;
}
}
}
File.WriteAllText(newaPath, sb.ToString());
}
static void ParseTxt()
{
string aPath = "a.txt";//16W+数据
string bPath = "b.txt";//2000+数据
string newaPath = "newa.txt";//与a.txt数据量相同
string[] arrA = File.ReadAllLines(aPath);
string b = File.ReadAllText(bPath);
StringBuilder sb = new StringBuilder();
bool isHave = false;
string titleTrim = string.Empty;
string subTitle = string.Empty;
char[] sChar = new char[] { ' ', '[', '[', '(', '『', '(', '{', '【' };
char[] eChar = new char[] { ' ', ']', '+', '/', '』', ']', ')', '-', '}', '】' };
foreach (string title in arrA)
{
titleTrim = title.TrimStart(sChar);
for (int i = 2; i < titleTrim.Length; i++)
{
isHave = false;
subTitle = titleTrim.Substring(0, i);
if (b.Contains(subTitle))
{
isHave = true;
}
if (!isHave)
{
if (i == 2)
{
sb.Append(title + "\t【未找到】\r\n");
}
else
{
sb.Append(title + "\t" + titleTrim.Substring(i - 1, titleTrim.Length - i + 1).TrimStart(eChar) + "\r\n");
}
break;
}
}
}
File.WriteAllText(newaPath, sb.ToString());
}