Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Lecture Windows programming - Chapter 7 introduce about String and Char. In this chapter, you will learn: String class, string class, char class, regular expressions. Inviting you to refer. | String, Char Chapter 7 Ebook: Beginning Visual C# 2010, chapter 5 Reference: C# How to Program, chapter 15 Contents String class StringBuilder class Char class Regular expressions Declare and Initialing strings Used as a type: Example: string st = "Dai Hoc Cong Nghiep"; Used as a class: new string (char[] mang_ki_tu); new String (char[] mang_ki_tu, int vi_tri_bat_dau, int so_ki_tu); new String (char ki_tu, int so_lan_lap); string var_name; string var_name = "value"; Example: Declare and Initialing strings string originalString, string1, string2, string3, string4; char[] characterArray = { 'b', 'i', 'r', 't', 'h', ' ', 'd', 'a', 'y' }; string output; originalString = "Welcome to C# programming!"; string1 = originalString; string2 = new string( characterArray ); string3 = new string( characterArray, 6, 3 ); string4 = new string( 'C', 5 ); output = "string1 = " + "\"" + string1 + "\"\n" + "string2 = " + "\"" + string2 + "\"\n" + "string3 = " + "\"" + string3 + "\"\n" + "string4 = " + "\"" + string4 + "\"\n"; MessageBox.Show( output, "String Class Constructors", MessageBoxButtons.OK, MessageBoxIcon.Information ); String4: tham số là ký tự và số lần lặp ký tự đó. String indexer, Length property String indexer Retrieval of any character in the string (using [] operator) Length property Returns the length of the string Example: string st = "abc", output=""; for ( int i=st.Length-1; i>=0; i-- ) output += st[i]; lblOutput.Text = output; String s=“abcxyz”; Char c = s[2]; String comparing methods Compare (static method) compares the values of two strings returns an integer value: string 1 = string 2 0 string 1 > string 2 1 string 1 < string 2 -1 CompareTo (not static method) compares the current string object to another string returns an integer value (same as Compare method) Equals determines whether two strings are the same, with a parameter specifies the culture, case, and sort rules used in the comparison returns true if two strings are the same String comparing . | String, Char Chapter 7 Ebook: Beginning Visual C# 2010, chapter 5 Reference: C# How to Program, chapter 15 Contents String class StringBuilder class Char class Regular expressions Declare and Initialing strings Used as a type: Example: string st = "Dai Hoc Cong Nghiep"; Used as a class: new string (char[] mang_ki_tu); new String (char[] mang_ki_tu, int vi_tri_bat_dau, int so_ki_tu); new String (char ki_tu, int so_lan_lap); string var_name; string var_name = "value"; Example: Declare and Initialing strings string originalString, string1, string2, string3, string4; char[] characterArray = { 'b', 'i', 'r', 't', 'h', ' ', 'd', 'a', 'y' }; string output; originalString = "Welcome to C# programming!"; string1 = originalString; string2 = new string( characterArray ); string3 = new string( characterArray, 6, 3 ); string4 = new string( 'C', 5 ); output = "string1 = " + "\"" + string1 + "\"\n" + "string2 = " + "\"" + string2 + "\"\n" + "string3 = " + "\"" + string3 + "\"\n" + "string4 = " + .