C#String.ToUpperInvariant方法
C#中的String.ToUpperInvariant()方法用于返回使用不变文化的大小写规则转换为大写形式的String对象的副本。
语法
语法如下-
public string ToUpperInvariant ();
示例
现在让我们看一个例子-
using System; using System.Text; public class Demo { public static void Main(String[] args) { string str1 = "one"; string str2 = "TWO"; string str3 = "ThrEE"; Console.WriteLine("String 1 = "+str1); Console.WriteLine("String1 ToUpperInvariant = "+str1.ToUpperInvariant()); Console.WriteLine("String 2 = "+str2); Console.WriteLine("String2 ToUpperInvariant = "+str2.ToUpperInvariant()); Console.WriteLine("String 3 = "+str3); Console.WriteLine("String3 ToUpperInvariant = "+str3.ToUpperInvariant()); } }
输出结果
String 1 = one String1 ToUpperInvariant = ONE String 2 = TWO String2 ToUpperInvariant = TWO String 3 = ThrEE String3 ToUpperInvariant = THREE
示例
using System; public class Demo { public static void Main(String[] args) { string str1 = "abcd"; string str2 = "PQRS"; Console.WriteLine("String 1 = "+str1); Console.WriteLine("String1 ToUpperInvariant = "+str1.ToUpperInvariant()); Console.WriteLine("String 2 = "+str2); Console.WriteLine("String2 ToUpperInvariant = "+str2.ToLowerInvariant()); } }
输出结果
String 1 = abcd String1 ToUpperInvariant = ABCD String 2 = PQRS String2 ToUpperInvariant = pqrs