C# 中请使用Contains判断字符串是否包含另一段字符串

∵ :使用Contains 比 IndexOf 的性能要高很多。

因为 Contains 是判断某个字符串是否在该字符串里面,而IndexOf是返回对应下标值

但是在使用contains的时候,注意转换大小写

1                 Console.WriteLine($"asdfghj包含asd ==> { "asdfghj".Contains("asd")}");
2                 Console.WriteLine($"asdfghj包含Asd ==> { "asdfghj".Contains("Asd")}");

猜你喜欢

转载自www.cnblogs.com/Katakana/p/10402683.html