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 498 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

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

DONG NAI UNIVERSITY OF TECHNOLOGYString Properties specified character position in the current String object.. DONG NAI UNIVERSITY OF TECHNOLOGYString Methods Name public bool Contains s

Trang 1

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 2

Represents text as a series

of Unicode characters.

Trang 3

DONG NAI UNIVERSITY OF TECHNOLOGY

Constructor

There are many overload Constructors I would like to tell you the Constructor below:

String Constructor ( Char [])

class to the value indicated by an array

of Unicode characters

Trang 4

(new char[]{'H','U','I'});

MessageBox.Show(strHUI);

String strHUI = new String

MessageBox.Show(strHUI);

Use string or String ?

Trang 5

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 6

“a”==“A”?false

“a”==“a”?true

Determines whether two specified strings have the same value

Inequality(!=)

“a”!=“A”?true

“a”!=“a”?false

Determines whether two specified strings have different values

Trang 7

DONG NAI UNIVERSITY OF TECHNOLOGY

String Properties

specified character position

in the current String object

characters in the current String object

Trang 8

( string strA, string strB )Description

and returns an integer that indicates

their relative position in the sort order

0 strA equals strB

-1 strA is less than strB

Trang 9

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 10

string strA, string strB,

bool ignoreCase )

Description

,ignoring or honoring their case, and

returns an integer that indicates their

relative position in the sort order

Trang 11

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

(“A", “a”,true);nRet=0

(“a", “A”,false);nRet=-1

(“A", “a”,false);nRet=1

Trang 12

Compares this instance with a

whether this instance precedes,

follows, or appears in the same

position in the sort order as the

specified String (0 ; 1 ; -1)

Trang 13

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 14

string str = string.Copy("Teo");

string str1 = "Ti";

string str2 =string.Copy(str1);

Trang 15

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Name

public bool Contains( string value )

Description

Returns a value indicating whether the

this string

Return true or false

Trang 16

string strA = "Trần Văn Tèo";

Trang 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

Trang 19

DONG NAI UNIVERSITY OF TECHNOLOGY

Determines whether the end of this

string instance matches the specified

string when compared using the

specified comparison option

Trang 21

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 array

Trang 22

strFormat = string.Format("Tỉ giá {0:d}

= {1:c}", DateTime.Today, 22.3);

MessageBox.Show(strFormat);

Trang 23

HO CHI MINH UNIVERSITY OF INDUSTRY

Author: Duy Thanh Tran – Phone : 0987773061 - Email: thanhxeiko@gmail.com – Blog: http://thanhxeiko.wordpress.com

Trang 24

occurrence of the specified Unicode

character in this string

of value if that character is found, or -1

if it is not

Trang 25

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 26

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

Trang 27

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string str = "Học! Học Nữa ! Học Mãi" ;

int nRet = str.IndexOf( "Học" );

Trang 28

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

Trang 29

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string strHUI = "Welcome C# 2010" ;

int nRet = strHUI.IndexOf( "WELCOME" ,

Trang 30

Reports the index of the first

occurrence in this instance of 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

Trang 31

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string str = "Không! không; có? có?" ;

int nRet=str.IndexOfAny( new char [] { '>' , '?' , ';' });

 nRet=12

Trang 32

string value )Description

of String at a specified index position

in this instance

Trang 33

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 34

Reports the index position 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

Trang 35

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 36

Reports the index position of the last

occurrence of a specified string within

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 the

last index position in this instance

Trang 37

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string str = "Học ! Học Nữa ! Học Mãi";

int nRet = str.LastIndexOf("Học");

nRet =16

nRet = str.LastIndexOf("HỌC");

Trang 38

StringComparison comparisonType )

Description

Reports the index of the last

occurrence of a specified string within

the current String object A parameter

specifies the type of search to use for

the specified string

Trang 39

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string str = "Học ! Học Nữa ! Học Mãi" ;

int nRet = str.LastIndexOf( "HỌC" ,

StringComparison OrdinalIgnoreCase);

 nRet =16

Trang 40

Deletes all the characters from this

string beginning at a specified position

and continuing through the last

position

Trang 41

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 42

int count )Description

Deletes a specified number of

beginning at a specified position

Trang 43

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 44

char newChar )Description

Returns a new string in which all

occurrences of a specified Unicode

character in this instance are replaced

character

Trang 45

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 46

string newValue )Description

Returns a new string in which all

occurrences of a specified string in the

current instance are replaced with

another specified string

Trang 47

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string str = "Phải xem tài liệu trước khi tới lớp, tài liệu

này rất quan trọng!" ;

str = str.Replace( "tài liệu" , "document" );

 str = "Phải xem document trước khi tới lớp,

document này rất quan trọng!" ;

Trang 48

separator )

Description

Returns a string array that contains

the substrings in this instance that are

delimited by elements of a specified

Unicode character array

Trang 49

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string str = "Trần văn tèo;21 tuổi;Chưa

vợ;Côn Đảo";

string []strArr=str.Split(new char[]{';'});

foreach (string s in strArr)

Trang 50

StringSplitOptions options )

Description

Returns a string array that contains

the substrings in this string that are

delimited by elements of a specified

string array A parameter specifies

whether to return empty array

elements

Trang 51

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Example

string str = "Trần văn tèo;;21 tuổi;Chưa vợ;Côn Đảo" ;

string []strArr=str.Split( new string [] { ";" },

Trang 52

string str = "Trần văn tèo;;21 tuổi;Chưa vợ;Côn Đảo" ;

string []strArr=str.Split( new string [] { ";" },

Trang 53

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Name

public bool StartsWith( string value )

Description

Determines whether the beginning of

this string instance matches the

specified string

Trang 55

DONG NAI UNIVERSITY OF TECHNOLOGY

Determines whether the beginning of

this string instance matches the

specified string when compared using

the specified comparison option

Trang 56

công</head>" ;

bool bStart=str.StartsWith( "<HEAD>" ,

StringComparison Ordinal);

MessageBox Show(bStart.ToString());False

bool bStart=str.StartsWith( "<HEAD>" ,

StringComparison OrdinalIgnoreCase);

True

Trang 57

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Name

public string Substring( int startIndex )

Description

Retrieves a substring from this

instance The substring starts at a

specified character position

Trang 58

string strSub = str.Substring(5);

MessageBox Show(strSub);

Trang 59

DONG NAI UNIVERSITY OF TECHNOLOGY

Retrieves a substring from this

instance The substring starts at a

specified character position and has a

specified length

Trang 60

string strSub = str.Substring(10,13);

MessageBox Show(strSub);

strSub = str.Substring(0,9);

Trang 61

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Name

public char[] ToCharArray()

Description

Copies the characters in this instance

to a Unicode character array

Trang 63

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 64

MessageBox Show(str);

 microsoft visual studio 2010

Trang 65

DONG NAI UNIVERSITY OF TECHNOLOGY

Trang 66

MessageBox Show(str);

MICROSOFT VISUAL STUDIO 2010

Trang 67

DONG NAI UNIVERSITY OF TECHNOLOGY

String Methods

Name

public string Trim()

Description

Removes all leading and trailing

current String object

Trang 68

MessageBox Show(str.Length+ "" ); //35

MessageBox Show(str);

 " Microsoft Visual Studio 2010 "

string str = " Microsoft Visual Studio 2010 " ;

Trang 69

DONG NAI UNIVERSITY OF TECHNOLOGY

Removes all trailing occurrences of a

set of characters specified in an array

Trang 70

str=str.TrimEnd(new char [] { ' ' , '?' , '!' , '#' });

MessageBox Show(str.Length+ "" );// 28

MessageBox Show(str);

 "Microsoft Visual Studio 2010"

Trang 71

DONG NAI UNIVERSITY OF TECHNOLOGY

Removes all leading occurrences of a

set of characters specified in an array

Trang 72

str=str.TrimStart(new char [] { ' ' , '?' , '!' , '#' });

MessageBox Show(str.Length+ "" );// 28

MessageBox Show(str);

 "Microsoft Visual Studio 2010"

Trang 73

DONG NAI UNIVERSITY OF TECHNOLOGY

DEMO String & Dictionary

Trang 74

END

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

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm