Checking multiple contains on one string

前端 未结 8 1329
孤独总比滥情好
孤独总比滥情好 2020-12-19 01:33

So I have a conditional that currently looks like this...

if (input.Contains(\",\") || input.Contains(\"/\") || input.Contains(@\"\\\") || input.Contains(\".         


        
相关标签:
8条回答
  • 2020-12-19 02:13

    Try

    If (input.IndexOfAny(new char[] { ',', '/', '\\', '.' }) >= 0) {
        ...
    }
    

    or

    If (input.IndexOfAny(@",/\.".ToCharArray()) >= 0) {
        ...
    }
    
    0 讨论(0)
  • 2020-12-19 02:14

    Does this win for shortest?

    @".,/\".Any(input.Contains)
    
    0 讨论(0)
提交回复
热议问题