1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài giảng lập trình c 2010 chương 6 đh đồng nai công nghệ đồng nai

74 497 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 74
Dung lượng 480,89 KB

Nội dung

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 string strHUI = new string (new char[]{'H','U','I'}); MessageBox.Show(strHUI); Use string or String? String strHUI = new String (new char[]{'H','U','I'}); MessageBox.Show(strHUI); DONG NAI UNIVERSITY OF TECHNOLOGY String Fields Empty Represents the empty string This field is read-only string strName = string.Empty; DONG NAI UNIVERSITY OF TECHNOLOGY String Operators Name Equality(==) “a”==“A”?false “a”==“a”?true Description Determines whether two specified strings have the same value Inequality(!=) “a”!=“A”?true “a”!=“a”?false Determines whether two specified strings have different values DONG NAI UNIVERSITY OF TECHNOLOGY String Properties Name Chars Description 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); MICROSOFT VISUAL STUDIO 2010 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string Trim() Description Removes all leading and trailing whitespace 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 [...]... MessageBox.Show( "c [" + strB+"] ở cuối chuỗi"); else MessageBox.Show("Ko c [" + strB + "] ở cuối chuỗi"); 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 DONG NAI UNIVERSITY OF TECHNOLOGY String... TECHNOLOGY String Methods Example string strHUI = "Welcome C# 2010" ; int nRet = strHUI.IndexOf("WELCOME", StringComparison.Ordinal); nRet =-1 int nRet = strHUI.IndexOf("WELCOME", StringComparison.OrdinalIgnoreCase); nRet =0 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public int IndexOfAny( char[] anyOf ) Description Reports the index of the first occurrence in this instance of any character... StringComparison.OrdinalIgnoreCase); if (bRet) MessageBox.Show( "c [" + strB+"] ở cuối chuỗi"); else MessageBox.Show("Ko c [" + strB + "] ở cuối chuỗi"); DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public static string Format (string format, params Object[] args ) Description Replaces the format item in a specified string with the string representation of a corresponding object in a specified... value ) Description Inserts a specified instance of String at a specified index position in this instance DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Không sợ , chỉ sợ không c ng bằng"; str=str.Insert(9, "thiếu"); string str = "Không sợ thiếu, chỉ sợ không c ng bằng"; DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public int LastIndexOf( char value ) Description Reports... 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 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,... str.IndexOf("H c" ); nRet =0 nRet = str.IndexOf(“Nữa"); nRet =9 nRet = str.IndexOf(“Dạy"); nRet =-1 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public int IndexOf( string value, StringComparison comparisonType) Description Reports the index of the first occurrence of the specified string in the current String object A parameter specifies the type of search to use for the specified string DONG NAI. .. any character in a specified array of Unicode characters The zero-based index position where any character in anyOf was found; -1 if no character in anyOf was found DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "Không! không; c ? c ?"; int nRet=str.IndexOfAny(new char[] { '>','?',';'}); nRet=12 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string Insert( int startIndex,... of the last occurrence of a specified Unicode character within this instance The zero-based index position of value if that character is found, or -1 if it is not DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "a , b, c; d; e; f, k"; int nRet=str.LastIndexOf(','); nRet=17 nRet=str.LastIndexOf(‘!'); nRet=-1 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public int LastIndexOf(string... String with the same value as a specified String string str = string.Copy("Teo"); string str1 = "Ti"; string str2 =string.Copy(str1); 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 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example... DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public int IndexOf( string value ) Description Reports the index of the first occurrence of the specified string in this instance The zero-based index position of value if that string is found, or -1 if it is not If value is String.Empty, the return value is 0 DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Example string str = "H c! H c Nữa ! Học ... DONG NAI UNIVERSITY OF TECHNOLOGY String Methods Name public string Replace( char oldChar, char newChar ) Description Returns a new string in which all occurrences of a specified Unicode character... instance are replaced with another specified 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";... 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

Ngày đăng: 03/12/2015, 18:32