How can I check if a string contains a character in C#?

后端 未结 8 988
陌清茗
陌清茗 2020-12-02 09:43

Is there a function I can apply to a string that will return true of false if a string contains a character.

I have strings with one or more character options such

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 10:14

    It will be hard to work in C# without knowing how to work with strings and booleans. But anyway:

            String str = "ABC";
            if (str.Contains('A'))
            { 
                //...
            }
    
            if (str.Contains("AB"))
            { 
                //...
            }
    

提交回复
热议问题