Check If String Contains All “?”

前端 未结 8 1201
离开以前
离开以前 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:04

    bool allQuestionMarks = input.All(c => c == '?');
    

    This uses the LINQ All method, which "determines whether all elements of a sequence satisfy a condition." In this case, the elements of the collection are characters, and the condition is that the character is equal to the question mark character.

提交回复
热议问题