intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Lập trình C# 2010: Chương 6 - ĐH Đồng Nai Công nghệ Đồng Nai

Chia sẻ: Na Na | Ngày: | Loại File: PPTX | Số trang:74

91
lượt xem
15
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Bài giảng Lập trình C# 2010: Chương 6 - String Class có nội dung trình bày về: Constructor, String Field, String Operators, String Methods, DEMO String & Dictionary.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Lập trình C# 2010: Chương 6 - ĐH Đồng Nai Công nghệ Đồng Nai

  1. DONG NAI UNIVERSITY OF TECHNOLOGY
  2. DONG NAI UNIVERSITY OF TECHNOLOGY String Class Represents text as a series of Unicode characters.
  3. DONG NAI UNIVERSITY OF TECHNOLOGY Constructor There are many overload Constructors. I would like to tell you the Constructor below: String Constructor ( Char []) Initializes a new instance of the String class to the value indicated by an array of Unicode characters.
  4. DONG NAI UNIVERSITY OF TECHNOLOGY Constructor string strHUI = new string (new char[] {'H','U','I'}); Use string or String? MessageBox.Show(strHUI); String strHUI = new String (new char[] {'H','U','I'}); MessageBox.Show(strHUI);
  5. DONG NAI UNIVERSITY OF TECHNOLOGY String Fields Empty Represents the empty string. This field is read-only. string strName = string.Empty;
  6. DONG NAI UNIVERSITY OF TECHNOLOGY String Operators Name Description Equality(==) Determines whether “a”==“A”?false two specified strings “a”==“a”?true have the same value. Inequality(!=) Determines whether “a”!=“A”?true two specified strings “a”!=“a”?false have different values.
  7. DONG NAI UNIVERSITY OF TECHNOLOGY String Properties Name Description Chars Gets the character at a specified character position in the current String object. char ch = strHUI[0]; Length Gets the number of characters in the current String object. int nSize = strHUI.Length;
  8. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public static int Compare ( string strA, string strB ) Description Compares two specified String objects and returns an integer that indicates their relative position in the sort order 0 strA equals strB 1 strA is greater than strB -1 strA is less than strB
  9. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example int nRet = string.Compare(“A", “a"); nRet=1 int nRet = string.Compare(“a", “A"); nRet=-1 int nRet = string.Compare(“a", “a"); nRet=0
  10. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public static int Compare( string strA, string strB, bool ignoreCase ) Description Compares two specified String objects ,ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order
  11. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example int nRet = string.Compare (“A", “a”,true);nRet=0 int nRet = string.Compare (“a", “A”,false);nRet=-1 int nRet = string.Compare (“A", “a”,false);nRet=1
  12. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public int CompareTo( string strB ) Description Compares this instance with a specified String object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified String. (0 ; 1 ; -1)
  13. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string strA = “A”; string strB = “B”; int nRet = strA.CompareTo(strB); nRet=-1 string strA = “A”; string strB = null; int nRet = strA.CompareTo(strB); nRet=1
  14. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public static string Copy(string str) Description Creates a new instance of String with the same value as a specified String. string str = string.Copy("Teo"); string str1 = "Ti"; string str2 =string.Copy(str1);
  15. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public bool Contains( string value ) Description Returns a value indicating whether the specified String object occurs within this string Return true or false
  16. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string strA = "Trần Văn Tèo"; string strB = "Văn"; bool bRet = strA.Contains(strB); if (!bRet) MessageBox.Show("Không có ["+strB+"] trong ["+strA+"]"); else MessageBox.Show("Có [" + strB + "] trong [" + strA + "]");
  17. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public bool EndsWith( string value ) Description Determines whether the end of this string instance matches the specified string Return true or false
  18. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string strA = "Tèo "; string strB = ""; bool bRet = strA.EndsWith(strB); if (bRet) MessageBox.Show("có [" + strB+"] ở cuối chuỗi"); else MessageBox.Show("Ko có [" + strB + "] ở cuối chuỗi");
  19. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public bool EndsWith( string value, StringComparison comparType ) Description Determines whether the end of this string instance matches the specified string when compared using the specified comparison option
  20. DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string strA = "Tèo"; string strB = ""; bool bRet = strA.EndsWith(strB, StringComparison.OrdinalIgnoreCase); if (bRet) MessageBox.Show("có [" + strB+"] ở cuối chuỗi"); else MessageBox.Show("Ko có [" + strB + "] ở cuối chuỗi");
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2