C#中字符串操作函数String.IndexOf (Char)方法
:2012-06-16 20:58:28
报告指定 Unicode 字符在此字符串中的第一个匹配项的索引。其原型为:
publicint IndexOf(char value)
参数value为要查找的 Unicode 字符。
返回值:如果找到该字符,则为 value 的从零开始的索引位置;如果未找到,则为 -1。
如:
string str = "翔宇亭IT乐园。";
int iPos = str.IndexOf('I');
其返回值为:3
同时,IndexOf方法还有其它8种重载形式:
(1)publicint IndexOf(string value)
(2)publicint IndexOf(char value, int startIndex)
(3)publicint IndexOf( string value, int startIndex)
(4)publicint IndexOf(string value,StringComparison comparisonType )
(5)publicint IndexOf(char value, int startIndex,int count )
(6)publicint IndexOf(string value,int startIndex,int count )
(7)publicint IndexOf(string value,int startIndex,StringComparison comparisonType )
(8)publicint IndexOf(string value,int startIndex,int count, StringComparison comparisonType )
C#中字符串操作函数String.IndexOf (Char)方法