我需要幫助來比較文本文件中按行拆分的兩個(gè)字符串值,并計(jì)算比較的字符串。我已經(jīng)嘗試了一些代碼但沒有得到它。它只需要一個(gè)值來比較。如何傳遞第二個(gè)值。所以包含方法返回 Bool 值我如何計(jì)算比較值。像這樣的文本文件: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貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊
創(chuàng)建一個(gè)不同的 IP 和瀏覽器組合列表只是 LINQ 魔術(shù)的幾行:
string[] lines = File.ReadAllLines("somefile.txt");
IEnumerable<string> fingerPrints = lines.Select(c => $"{c.Split(",").First()}
{c.Split(",").Last()}").Distinct();
您現(xiàn)在有一個(gè)可枚舉的字符串,其中每個(gè)條目都是唯一的/不同的。您可以將它們寫入另一個(gè)文件,或使用它們來更新原始文件。
- 1 回答
- 0 關(guān)注
- 124 瀏覽
添加回答
舉報(bào)
0/150
提交
取消