C 中String型別的常用方法

2021-09-13 04:09:46 字數 4439 閱讀 7016

序號

方法名稱 & 描述1

public static int compare( string stra, string strb )

比較兩個指定的 string 物件,並返回乙個表示它們在排列順序中相對位置的整數。該方法區分大小寫。 2

public static int compare( string stra, string strb, bool ignorecase )

比較兩個指定的 string 物件,並返回乙個表示它們在排列順序中相對位置的整數。但是,如果布林引數為真時,該方法不區分大小寫。 3

public static string concat( string str0, string str1 )

連線兩個 string 物件。 4

public static string concat( string str0, string str1, string str2 )

連線三個 string 物件。 5

public static string concat( string str0, string str1, string str2, string str3 )

連線四個 string 物件。 6

public bool contains( string value )

返回乙個表示指定 string 物件是否出現在字串中的值。 7

public static string copy( string str )

建立乙個與指定字串具有相同值的新的 string 物件。 8

public void copyto( int sourceindex, char destination, int destinationindex, int count )

從 string 物件的指定位置開始複製指定數量的字元到 unicode 字元陣列中的指定位置。 9

public bool endswith( string value )

判斷 string 物件的結尾是否匹配指定的字串。 10

public bool equals( string value )

判斷當前的 string 物件是否與指定的 string 物件具有相同的值。 11

public static bool equals( string a, string b )

判斷兩個指定的 string 物件是否具有相同的值。 12

public static string format( string format, object arg0 )

把指定字串中乙個或多個格式項替換為指定物件的字串表示形式。 13

public int indexof( char value )

返回指定 unicode 字元在當前字串中第一次出現的索引,索引從 0 開始。 14

public int indexof( string value )

返回指定字串在該例項中第一次出現的索引,索引從 0 開始。 15

public int indexof( char value, int startindex )

返回指定 unicode 字元從該字串中指定字元位置開始搜尋第一次出現的索引,索引從 0 開始。 16

public int indexof( string value, int startindex )

返回指定字串從該例項中指定字元位置開始搜尋第一次出現的索引,索引從 0 開始。 17

public int indexofany( char anyof )

返回某乙個指定的 unicode 字元陣列中任意字元在該例項中第一次出現的索引,索引從 0 開始。 18

public int indexofany( char anyof, int startindex )

返回某乙個指定的 unicode 字元陣列中任意字元從該例項中指定字元位置開始搜尋第一次出現的索引,索引從 0 開始。 19

public string insert( int startindex, string value )

返回乙個新的字串,其中,指定的字串被插入在當前 string 物件的指定索引位置。 20

public static bool isnullorempty( string value )

指示指定的字串是否為 null 或者是否為乙個空的字串。 21

public static string join( string separator, string value )

連線乙個字串陣列中的所有元素,使用指定的分隔符分隔每個元素。 22

public static string join( string separator, string value, int startindex, int count )

連線接乙個字串陣列中的指定位置開始的指定元素,使用指定的分隔符分隔每個元素。 23

public int lastindexof( char value )

返回指定 unicode 字元在當前 string 物件中最後一次出現的索引位置,索引從 0 開始。 24

public int lastindexof( string value )

返回指定字串在當前 string 物件中最後一次出現的索引位置,索引從 0 開始。 25

public string remove( int startindex )

移除當前例項中的所有字元,從指定位置開始,一直到最後乙個位置為止,並返回字串。 26

public string remove( int startindex, int count )

從當前字串的指定位置開始移除指定數量的字元,並返回字串。 27

public string replace( char oldchar, char newchar )

把當前 string 物件中,所有指定的 unicode 字元替換為另乙個指定的 unicode 字元,並返回新的字串。 28

public string replace( string oldvalue, string newvalue )

把當前 string 物件中,所有指定的字串替換為另乙個指定的字串,並返回新的字串。 29

public string split( params char separator )

返回乙個字串陣列,包含當前的 string 物件中的子字串,子字串是使用指定的 unicode 字元陣列中的元素進行分隔的。 30

public string split( char separator, int count )

返回乙個字串陣列,包含當前的 string 物件中的子字串,子字串是使用指定的 unicode 字元陣列中的元素進行分隔的。int 引數指定要返回的子字串的最大數目。 31

public bool startswith( string value )

判斷字串例項的開頭是否匹配指定的字串。 32

public char tochararray()

返回乙個帶有當前 string 物件中所有字元的 unicode 字元陣列。 33

public char tochararray( int startindex, int length )

返回乙個帶有當前 string 物件中所有字元的 unicode 字元陣列,從指定的索引開始,直到指定的長度為止。 34

public string tolower()

把字串轉換為小寫並返回。 35

public string toupper()

把字串轉換為大寫並返回。 36

public string trim()

移除當前 string 物件中的所有前導空白字元和後置空白字元。

js中String型別的常用方法

var str1 new string hello var str2 new string hello document.write 兩個字串的物件一樣嗎?str1.tostring str2.tostring 建立乙個字串的方式 方式1 new string 字串的內容 方式2 var str 字...

c 入門 string型別的常用方法

string a newstring aaa string b newstring aaa console.writeline a b 使用了new,他們將生成兩個不一樣的本體,但他們仍判斷內容 運算子的運算方式是可以修改的 string s1 hello string s2 s1 s1 world...

C 中String的常用方法

特點 1.可以看作是乙個唯讀的char陣列 2.不可變性,即字串中的字元內容不能改,當重新給改變量賦值時,知識變數的指向改變了,但可以讀。如果我 想 改變 字串中字元的內容,怎麼辦那?實際上原字串的內容沒有改變 解決方案 利用char陣列進行修改 1 把字串變成字元陣列,tochararray 2 ...