Changing case of a string to Upper, Lower or Title


/ Published in: C#
Save to your folder(s)

From MSDN, changing case of a string to Upper, Lower or Title


Copy this code and paste it in your HTML
  1. using System;
  2. using System.Globalization;
  3.  
  4.  
  5. public class SamplesTextInfo {
  6.  
  7. public static void Main() {
  8.  
  9. // Defines the string with mixed casing.
  10. string myString = "wAr aNd pEaCe";
  11.  
  12. // Creates a TextInfo based on the "en-US" culture.
  13. TextInfo myTI = new CultureInfo("en-US",false).TextInfo;
  14.  
  15. // Changes a string to lowercase.
  16. Console.WriteLine( "\"{0}\" to lowercase: {1}", myString, myTI.ToLower( myString ) );
  17.  
  18. // Changes a string to uppercase.
  19. Console.WriteLine( "\"{0}\" to uppercase: {1}", myString, myTI.ToUpper( myString ) );
  20.  
  21. // Changes a string to titlecase.
  22. Console.WriteLine( "\"{0}\" to titlecase: {1}", myString, myTI.ToTitleCase( myString ) );
  23.  
  24. }
  25.  
  26. }
  27.  
  28. /*
  29. This code produces the following output.
  30.  
  31. "wAr aNd pEaCe" to lowercase: war and peace
  32. "wAr aNd pEaCe" to uppercase: WAR AND PEACE
  33. "wAr aNd pEaCe" to titlecase: War And Peace
  34.  
  35. */

URL: https://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.