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

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

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

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.

DONG NAI UNIVERSITY OF TECHNOLOGY DONG NAI UNIVERSITY OF TECHNOLOGY String Class Represents text as a series of Unicode characters 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 DONG NAI UNIVERSITY OF TECHNOLOGY Constructor strin g strH U I= new strin g (new char[]{'H ','U ','I'}); M essageBox.Show (strH U I); Use string or S trin g ? S trin g strH U I= new S trin g (new char[]{'H ','U ','I'}); M essageBox.Show (strH U I); DONG NAI UNIVERSITY OF TECHNOLOGY String Fields Empty Represents the empty string This field is readonly string strName = string.Empty; DONG NAI UNIVERSITY OF TECHNOLOGY String Operators Name Description Equality(==) Determines whether two specified “a”==“A”?false strings have the same value “a”==“a”?true Inequality(!=) Determines whether two specified “a”!=“A”?true strings have different values “a”!=“a”?false 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; 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 strA equals strB strA is greater than strB -1 strA is less than strB 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 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 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Microsoft Visual Studio 2010"; string strSub = str.Substring(10,13); MessageBox.Show(strSub); Visual Studio strSub = str.Substring(0,9); Microsoft DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public char[] ToCharArray() Description Copies the characters in this instance to a Unicode character array DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Microsoft Visual Studio 2010"; char []chrArr=str.ToArray(); MessageBox.Show(chrArr.Length+"");//28 foreach (char c in chrArr) { MessageBox.Show(c.ToString()); } DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string ToLower() Description Returns a copy of this string converted to lowercase DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Microsoft Visual Studio 2010"; str=str.ToLower(); MessageBox.Show(str); microsoft visual studio 2010 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string ToUpper() Description Returns a copy of this string converted to uppercase DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Microsoft Visual Studio 2010"; str=str.ToUpper(); MessageBox.Show(str); M ICRO SO FT VISU AL STU D IO 2010 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string Trim() Description Removes all leading and trailing white-space characters from the current String object DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = " Microsoft Visual Studio 2010 "; MessageBox.Show(str.Length+"");//35 MessageBox.Show(str); " Microsoft Visual Studio 2010 " string str = " Microsoft Visual Studio 2010 str=str.Trim(); MessageBox.Show(str.Length+""); //28 MessageBox.Show(str); str = "Microsoft Visual Studio 2010"; "; DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string TrimEnd( params char[] trimChars ) Description Removes all trailing occurrences of a set of characters specified in an array from the current String object DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Microsoft Visual Studio 2010 #?! #"; str=str.TrimEnd(new char[] { ' ','?','!','#' }); MessageBox.Show(str.Length+"");//28 MessageBox.Show(str); "Microsoft Visual Studio 2010" DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string TrimStart( params char[] trimChars ) Description Removes all leading occurrences of a set of characters specified in an array from the current String object DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = " #?! #Microsoft Visual Studio 2010"; str=str.TrimStart(new char[] { ' ','?','!','#' }); MessageBox.Show(str.Length+"");//28 MessageBox.Show(str); "Microsoft Visual Studio 2010" DONG NAI UNIVERSITY OF TECHNOLOGY DEMO String & Dictionary DONG NAI UNIVERSITY OF TECHNOLOGY END ... Unicode character DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Chúc em học tốt"; str = str.Replace(' ','#'); str = "Chúc#các#em#học#tốt"; DONG NAI UNIVERSITY OF TECHNOLOGY... DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Không sợ , sợ không công bằng"; str=str.Insert(9, "thiếu"); string str = "Không sợ thiếu, sợ không công bằng"; DONG NAI. .. UNIVERSITY OF INDUSTRY Author: Duy Thanh Tran – Phone : 0987773 061 - Email: thanhxeiko@gmail.com – Blog: http://thanhxeiko.wordpress.com DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public int

Ngày đăng: 08/05/2021, 12:17

Từ khóa liên quan

Mục lục

  • Slide 1

  • Slide 2

  • Slide 3

  • Slide 4

  • Slide 5

  • Slide 6

  • Slide 7

  • Slide 8

  • Slide 9

  • Slide 10

  • Slide 11

  • Slide 12

  • Slide 13

  • Slide 14

  • Slide 15

  • Slide 16

  • Slide 17

  • Slide 18

  • Slide 19

  • Slide 20

Tài liệu cùng người dùng

Tài liệu liên quan