code_junkie

Is there a built-in IsLowerCase() in .NET?

Nov 13th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. public static bool IsLowerCase( this string text ) {
  2. if ( string.IsNullOrEmpty( text ) ) { return true; }
  3. foreach ( char c in text )
  4. if ( char.IsLetter( c ) && !char.IsLower( c ) )
  5. return false;
  6.  
  7. return true;
  8. }
  9.  
  10.  
  11. "someString".IsLowerCase();
  12.  
  13. char.IsLower(c);
  14.  
  15. string upper = "CONVERTED FROM UPPERCASE";
  16. Console.WriteLine(upper.ToLower());
  17.  
  18. CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
  19. TextInfo textInfo = cultureInfo.TextInfo;
  20.  
  21. Console.WriteLine(textInfo.ToTitleCase(title));
  22. Console.WriteLine(textInfo.ToLower(title));
  23. Console.WriteLine(textInfo.ToUpper(title));
  24.  
  25. string s = ...
  26. s.All(c => char.IsLower(c));
  27.  
  28. s.ToLower(CultureInfo.CurrentUICulture) == s;
  29.  
  30. Imports System.Runtime.CompilerServices
  31. Module CustomExtensions
  32.  
  33. <Extension()> _
  34. Public Function IsLowerCase(ByVal Input As String) As Boolean
  35. Return Return Input.All(Function(c) Char.IsLower(c))
  36. End Function
  37.  
  38. End Module
  39.  
  40. using System.Runtime.CompilerServices;
  41. static class CustomExtensions
  42. {
  43. public static bool IsLowerCase(this string Input)
  44. {
  45. return Input.All(c => char.IsLower(c));
  46. }
  47. }
  48.  
  49. Console.WriteLine("ThisIsMyTestString".IsLowerCase())
  50.  
  51. public bool IsLower(string TestString)
  52. {
  53. if (String.IsNullOrEmpty(TestString))
  54. {
  55. return true;
  56. }
  57.  
  58. string testlower = TestString.ToLowerInvariant();
  59.  
  60. if (String.Compare(TestString, testlower, false) == 0)
  61. {
  62. return true;
  63. }
  64. else
  65. {
  66. return false;
  67. }
  68.  
  69.  
  70. }
  71.  
  72. return Input.ToList().Exists(c => Char.IsUpper(c));
  73.  
  74. char.IsLetter( c )
Add Comment
Please, Sign In to add comment