The previously blogged System.Globalization.CultureInfo
class has some useful methods for converting text to upper case, lower case, and title case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
PS> [System.Globalization.CultureInfo]::CurrentCulture | gm TypeName: System.Globalization.CultureInfo Name MemberType Definition ---- ---------- ---------- ClearCachedData Method System.Void ClearCachedData() Clone Method System.Object Clone() ... NumberFormat Property System.Globalization.NumberFormatInfo NumberFormat {get;set;} OptionalCalendars Property System.Globalization.Calendar[] OptionalCalendars {get;} Parent Property System.Globalization.CultureInfo Parent {get;} TextInfo Property System.Globalization.TextInfo TextInfo {get;} ThreeLetterISOLanguageName Property System.String ThreeLetterISOLanguageName {get;} ... PS> [System.Globalization.CultureInfo]::CurrentCulture.TextInfo ANSICodePage : 1252 OEMCodePage : 850 MacCodePage : 10000 EBCDICCodePage : 20285 LCID : 2057 CultureName : en-GB IsReadOnly : False ListSeparator : , IsRightToLeft : False PS> [System.Globalization.CultureInfo]::CurrentCulture.TextInfo | gm TypeName: System.Globalization.TextInfo Name MemberType Definition ---- ---------- ---------- Clone Method System.Object Clone() Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToLower Method char ToLower(char c), string ToLower(string str) ToString Method string ToString() ToTitleCase Method string ToTitleCase(string str) ToUpper Method char ToUpper(char c), string ToUpper(string str) ANSICodePage Property System.Int32 ANSICodePage {get;} CultureName Property System.String CultureName {get;} EBCDICCodePage Property System.Int32 EBCDICCodePage {get;} IsReadOnly Property System.Boolean IsReadOnly {get;} IsRightToLeft Property System.Boolean IsRightToLeft {get;} LCID Property System.Int32 LCID {get;} ListSeparator Property System.String ListSeparator {get;set;} MacCodePage Property System.Int32 MacCodePage {get;} OEMCodePage Property System.Int32 OEMCodePage {get;} |
These methods can be used thus:
1 2 3 4 5 6 |
PS> [System.Globalization.CultureInfo]::CurrentCulture.TextInfo.ToUpper("some text") SOME TEXT PS> [System.Globalization.CultureInfo]::CurrentCulture.TextInfo.ToTitleCase("some text") Some Text PS> [System.Globalization.CultureInfo]::CurrentCulture.TextInfo.ToLower("Some TEXT") some text |
Good to know!