我需要帮助来比较文本文件中按行拆分的两个字符串值,并计算比较的字符串。我已经尝试了一些代码但没有得到它。它只需要一个值来比较。如何传递第二个值。所以包含方法返回 Bool 值我如何计算比较值。像这样的文本文件:172.16.50.70,[17/Aug/2017:08:36:36,GET /login2.php HTTP/1.0,200,1575,-,"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"172.16.50.70,[17/Aug/2017:08:36:37,GET /objections/login.php HTTP/1.0,200,1988,-,"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"39.51.52.189,[17/Aug/2017:08:36:37,GET /objections/css/style.css HTTP/1.1,200,6198,googleusercontent.com/search?q=cache:aiou.edu.pk/objections/ssearch.php,"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.39 Safari/537.36"代码string Files = System.IO.File.ReadAllText(@"C:\info.txt");string[] SplitByLine = Files.Split('\n');foreach (var item in SplitByLine){ string[] OneRowSplit = item.Split(','); GetIP = OneRowSplit[0]; LapInfo = OneRowSplit.Last(); string Filess = System.IO.File.ReadAllText(@"C:\info.txt"); string[] SplitByLines = Filess.Split('\n'); string ads = SplitByLines.Contains(GetIP & LapIngo).count(); // this line of code is not valid its only for telling i want some thing like this contain method take only one parameter and i also want to count comapred values}
1 回答
千万里不及你
TA贡献1784条经验 获得超9个赞
创建一个不同的 IP 和浏览器组合列表只是 LINQ 魔术的几行:
string[] lines = File.ReadAllLines("somefile.txt");
IEnumerable<string> fingerPrints = lines.Select(c => $"{c.Split(",").First()}
{c.Split(",").Last()}").Distinct();
您现在有一个可枚举的字符串,其中每个条目都是唯一的/不同的。您可以将它们写入另一个文件,或使用它们来更新原始文件。
- 1 回答
- 0 关注
- 87 浏览
添加回答
举报
0/150
提交
取消