最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net indexOf() 查找指定的字符串在字符串中得位置
时间:2022-06-25 04:01:02 编辑:袖梨 来源:一聚教程网
查找字串中指定字符或字串首次出现的位置,返首索引值,如:
| 代码如下 | 复制代码 |
| str1.IndexOf("字"); //查找"字"在str1中的索引值(位置) str1.IndexOf("字串");//查找"字串"的第一个字符在str1中的索引值(位置) str1.IndexOf("字串",3,2);//从str1第4个字符起,查找2个字符,查找"字串"的第一个字符在str1中的索引值(位置) |
|
实例
| 代码如下 | 复制代码 |
|
string str = "ok is ok"; |
|
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); |
|
相关文章
- 境界斩魂之刃东仙要二段大招有什么玩法技巧 12-10
- 九牧之野兴汉枪阵容玩法攻略分享 12-10
- 如鸢刘繇强度如何 12-10
- 九牧之野魏毒盾阵容怎么搭配 12-10
- 明日方舟终末地酮化植物如何获取 12-10
- 明日方舟终末地装备如何精锻 12-10