My first implementation idea is to do simply:
bool hasUpperCase (string str) { if(string.IsNullOrEmpty(str)) return false; for (int i = 0; i < str.Length; i++) { if (char.IsUpper (str[i])) return true; } return false; }
but maybe there is another faster way to do that ?
C isupper() The isupper() function checks whether a character is an uppercase alphabet (A-Z) or not.
The string isupper() method returns True if all cased characters in a string are uppercase. Otherwise, it returns False . If the string doesn't contain any cased characters, the isupper() method also returns False .
The islower() method returns True if all alphabets in a string are lowercase alphabets. If the string contains at least one uppercase alphabet, it returns False.
The isupper() function checks if ch is in uppercase as classified by the current C locale. By default, the characters from A to Z (ascii value 65 to 90) are uppercase characters.
You could reduce that to
bool HasUpperCase (string str) { return !string.IsNullOrEmpty(str) && str.Any(c => char.IsUpper(c)); }
using LINQ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With