Check If String Contains All “?”

前端 未结 8 1251
离开以前
离开以前 2021-01-17 11:35

How can I check if a string contains all question marks? Like this:

string input = \"????????\";

8条回答
  •  春和景丽
    2021-01-17 12:21

    Not very readable... But a regular expression is another way to do it (and it's fast):

    // Looking for a string composed only by one or more "?":
    bool allQuestionMarks = Regex.IsMatch(input, "^\?+$");
    

提交回复
热议问题