String contains another two strings

前端 未结 17 1570
故里飘歌
故里飘歌 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:21

    You could write an extension method with linq.

    public static bool MyContains(this string str, params string[] p) {
     return !p.Cast().Where(s => !str.Contains(s)).Any();
    }
    

    EDIT (thx to sirid):

    public static bool MyContains(this string str, params string[] p) {
     return !p.Any(s => !str.Contains(s));
    }
    

提交回复
热议问题