Computer >> Máy Tính >  >> Lập trình >> C#

Phương thức C # ToUpper ()

Phương thức ToUpper () trong C # được sử dụng để trả về bản sao của chuỗi này được chuyển đổi thành chữ hoa.

Cú pháp

 public string ToUpper (); 

Ví dụ

 using System; public class Demo {public static void Main (String [] args) {string str1 ="Chào mừng!"; string str2 ="Thisisit!"; char [] arr1 =str1.ToCharArray (3,2); char [] arr2 =str2.ToCharArray (2,2); Console.WriteLine ("String1 =" + str1); Console.WriteLine ("String1 ToUpper =" + str1.ToUpper ()); Console.WriteLine ("String1 Substring from index4 =" + str1.Substring (4, 4)); Console.Write ("Mảng ký tự ... String1 ="); for (int i =0; i  

Đầu ra

 String1 =Welcome! String1 ToUpper =WELCOME! String1 Substring from index4 =ome! Character array ... String1 =c oString2 =Thisisit! String2 ToUpper =thisISIT! / pre> 

Ví dụ

 using System; using System.Globalization; public class Demo {public static void Main (String [] args) {string str1 ="JackSparrow!"; string str2 ="@ # $ PQRSTUV!"; Console.WriteLine ("String1 =" + str1); Console.WriteLine ("String1 ToUpper =" + str1.ToUpper (new CultureInfo ("en-US", false))); Console.WriteLine ("String1 Substring from index4 =" + str1.Substring (2, 2)); Console.WriteLine ("\ n \ nString2 =" + str2); Console.WriteLine ("String2 ToUpper =" + str2.ToUpper (new CultureInfo ("en-US", false))); Console.WriteLine ("String2 Substring from index2 =" + str2.Substring (0, 5)); }} 

Đầu ra

 String1 =JackSparrow! String1 ToUpper =JACKSPARROW! String1 Chuỗi con từ index4 =ckString2 =@ # $ PQRSTUV! String2 ToUpper =@ # $ PQRSTUV! Chuỗi con String2 từ index2 =@ # $ PQ