This article provides five methods to determine whether a string contains capital characters and its implementation source code for your implementation reference.
Method 1: First determine whether the string is empty, and then determine whether it is a capital letter by character.
bool hasUpperCase (string str) { if((str)) return false; for (int i = 0; i < ; i++) { if ( (str[i])) return true; } return false; }
Method 2: Any method using strings
bool HasUpperCase (string str) { return !(str) && (c => (c)); }
Method 3: Convert to uppercase and compare whether it is equal
bool hasUpperCase (string str) { if((str)) return false; return str != (); }
Method 4: Regular matching method to determine whether characters containing A~Z
bool testCaseTwo(string str) { bool result = false; if ((str)) { return false; } result = (str, "\"[A-Z]\""); return result; } // Compact versionbool hasUpperCase(string str) { if ((str)) return false; return (str, "\"[A-Z]\""); }
Method 5: Make judgments based on the ASCII code to determine whether the ASCII code of the character is between 64 and 91
static bool testCaseFour(string str) { bool result = false; if ((str)) { return false; } for (int i = 0; i < ; i++) { if (str[i] > 64 && str[i] < 91) { result = true; break; } } return result; }
The above is the detailed content of five methods to use C# to determine whether a string contains capital characters. For more information on whether C# determines whether a string contains capital characters, please pay attention to my other related articles!