gpt4 book ai didi

c# - 计算特定字符串组合的行数

转载 作者:太空宇宙 更新时间:2023-11-03 13:44:31 24 4
gpt4 key购买 nike

我正在数数没有。 ProductServices 和 Add Product 出现的行数。

日志是:

INFO [ProductServices] Add Product has been performed by gulanand on product with id 424 () INFO [ProductServices] Add Product has been performed by gulanand on product with id 424 () INFO [ProductServices] Add Product has been performed by gulanand on product with id 424 () INFO [ProductServices] Update Product has been performed by gulanand on product with id 424 () INFO [ProductServices] Update Product has been performed by gulanand on product with id 424 () INFO [ProductServices] Add Product has been performed by gulanand on product with id 424 () INFO [ProductServices] Add Product has been performed by gulanand on product with id 424 () INFO [ProductServices] Add Product has been performed by gulanand on product with id 424 ()

我试过的代码是:

IEnumerable<string> textLines =
Directory.GetFiles(@"C:\Users\karansha\Desktop\Ashish Logs\", "*.*")
.Select(filePath => File.ReadAllLines(filePath))
.SelectMany(line => line);

List<string> users = new List<string>();

Regex r = new Regex(@"*ProductServices\sAdd Product");
foreach (string Line in textLines)
{
if (r.IsMatch(Line))
{
users.Add(Line);
}
}
//string[] textLines1 = new List<string>(users).ToArray();
int countlines = users.Count();
Console.WriteLine("ProductsCreated=" + countlines);

最佳答案

这是你想要的吗?

 int count = File.ReadAllLines().Count(x=>x.Contains("MONKEY"));

Linq 是 Luvly!

关于c# - 计算特定字符串组合的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15829582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com