String contains another two strings

前端 未结 17 1549
故里飘歌
故里飘歌 2020-12-15 07:12

Is it possible to have the contain function find if the string contains 2 words or more? This is what I\'m trying to do:

string d = \"You hit someone for 50          


        
17条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 07:34

    public static class StringExtensions
    {
        public static bool Contains(this string s, params string[] predicates)
        {
            return predicates.All(s.Contains);
        }
    }
    
    string d = "You hit someone for 50 damage";
    string a = "damage";
    string b = "someone";
    string c = "you";
    
    if (d.Contains(a, b))
    {
        Console.WriteLine("d contains a and b");
    }
    

提交回复
热议问题