YOMEDIA
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
95
lượt xem
16
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.
AMBIENT/
Chủ đề:
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
- 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'});
Use string or String?
MessageBox.Show(strHUI);
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 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.
- 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
0 strA equals strB
1 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
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,
follows, or appears in the same
position in the sort order as the
specified String. (0 ; 1 ; -1)
- 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
- 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);
- 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
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 + "]");
- 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
- 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");
- 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 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");
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
ERROR:connection unexpectedly closed (timed out?)
ERROR:connection unexpectedly closed (timed out?)
Đang xử lý...