Check If String Contains All “?”

前端 未结 8 1194
离开以前
离开以前 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, "^\?+$");
    
    0 讨论(0)
  • 2021-01-17 12:21

    You can also try this:

    private bool CheckIfStringContainsOnlyQuestionMark(string value)
    {
        return !value.Where(a => a != '?').Select(a => true).FirstOrDefault();
    }
    
    0 讨论(0)
提交回复
热议问题