Jquery中文网 >
脚本编程 >
Asp.net >
正文 asp.net indexOf() 查找指定的字符串在字符串中得位置
asp.net indexOf() 查找指定的字符串在字符串中得位置
发布时间:2016-12-03 编辑:www.jquerycn.cn
jquery中文网为您提供asp.net indexOf() 查找指定的字符串在字符串中得位置等资源,欢迎您收藏本站,我们将为您提供最新的asp.net indexOf() 查找指定的字符串在字符串中得位置资源
indexOf 查找指定的字符串在字符串中得位置,第一个参数是要查找的字符串 第2个参数起始位置
查找字串中指定字符或字串首次出现的位置,返首索引值,如:
代码如下 | 复制代码 |
str1.IndexOf("字"); //查找"字"在str1中的索引值(位置) str1.IndexOf("字串");//查找"字串"的第一个字符在str1中的索引值(位置) str1.IndexOf("字串",3,2);//从str1第4个字符起,查找2个字符,查找"字串"的第一个字符在str1中的索引值(位置) 实例
代码如下 | 复制代码 | string str = "ok is ok"; Console.WriteLine(str.IndexOf("ok")); Console.WriteLine(str.IndexOf("ok",1)); microsoft.com网站说明 下面的示例演示如何使用 indexOf 函数查找指定项的索引位置。 返回的索引是在 item 中指定的项的第一次出现。 再次调用该函数,并指定大于所找到元素的索引的起始索引值,可查找 item 的下一次出现。 JScript
代码如下 | 复制代码 | var a = ['red', 'blue', 'green', 'blue']; var myFirstIndex = Array.indexOf(a, "blue"); // View the results: "1" alert("myFirstIndex: " myFirstIndex); var mySecondIndex = Array.indexOf(a, "blue", (myFirstIndex 1) ); // View the results: "3" alert("mySecondIndex: " mySecondIndex); PH
代码如下 | 复制代码 | var a = ['red', 'blue', 'green', 'blue']; var myFirstIndex = Array.indexOf(a, "blue"); // View the results: "1" alert("myFirstIndex: " myFirstIndex); var mySecondIndex = Array.indexOf(a, "blue", (myFirstIndex 1) ); // View the results: "3" alert("mySecondIndex: " mySecondIndex); [关闭] |
|
|
|