Check If String Contains All “?”

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

    So many linq answers! Can't we do anything the old-fashioned way any more? This is an order of magnitude faster than the linq solution. More readable? Maybe not, but that is what method names are for.

        static bool IsAllQuestionMarks(String s) {
    
            for(int i = 0; i < s.Length; i++)
                if(s[i] != '?')
                    return false;
    
            return true;
        }
    

提交回复
热议问题