IndexOf(char value,int startIndex)函數(shù)是IndexOf重載函數(shù)形式之一,其從指定的startIndex位置開始查找指定的字符value,如果字符串中包含value值,則返回其第一次出現(xiàn)的位置(該位置從索引0開始)。該函數(shù)的原型為:
public int IndexOf( char value, int startIndex )
參數(shù):
value就是要查找的字符,startIndex就是搜索的起始位置。
返回值:
該函數(shù)的返回值為整型(int)。如果找到該字符,則返回值為value 的從零開始的索引位置;如果未找到,則返回值為 -1。
此方法執(zhí)行順序搜索,即僅當(dāng) Unicode 標(biāo)量值相同時(shí)兩個(gè)字符才被視為相等。
舉例如下:
string str = "武林網(wǎng)VEVB,你我共同的樂(lè)園。";
int iPos = str.IndexOf(7,'樂(lè)');
這個(gè)例子中,iPos的值為13,而不是5,原因是指定了搜索的起始位置為7,即從位置7后開始搜索相應(yīng)的字符。
該函數(shù)還有其它8種重載形式:
(1)public int IndexOf(char value)
(2)public int IndexOf(string value)
(3)public int IndexOf( string value, int startIndex)
(4)public int IndexOf(string value,StringComparison comparisonType )
(5)public int IndexOf(char value, int startIndex,int count )
(6)public int IndexOf(string value,int startIndex,int count )
(7)public int IndexOf(string value,int startIndex,StringComparison comparisonType )
(8)public int IndexOf(string value,int startIndex,int count, StringComparison comparisonType )
新聞熱點(diǎn)
疑難解答
圖片精選