IndexOf的用法
来源:互联网 发布:python re 正则表达式 编辑:程序博客网 时间:2024/05/17 22:01
IndexOf()
查找字串中指定字符或字串首次出现的位置,返首索引值,如:
str1.IndexOf("字"); //查找“字”在str1中的索引值(位置)
str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)
str1.IndexOf("字",start,end);//从str1第start+1个字符起,查找end个字符,查找“字”在字符串STR1中的位置[从第一个字符算起]注意:start+end不能大于str1的长度
indexof参数为string,在字符串中寻找参数字符串第一次出现的位置并返回该位置。如string s="0123dfdfdf";int i=s.indexof("df");这时i==4。
如果需要更强大的字符串解析功能应该用Regex类,使用正则表达式对字符串进行匹配。
indexof() :在字符串中从前向后定位字符和字符串;所有的返回值都是指在字符串的绝对位置,如为空则为- 1
string test="asdfjsdfjgkfasdsfsgfhgjgfjgdddd";
test.indexof(’d’) =2 //从前向后 定位 d 第一次出现的位置
test.indexof(’d’,1) =2 //从前向后 定位 d 从第三个字符串 第一次出现的位置
test.indexof(’d’,5,2) =6 //从前向后 定位 d 从第5 位开始查,查2位,即 从第5位到第7位;
lastindexof() :在字符串中从后向前定位字符和字符串;、
用法和 indexof() 完全相同。
- indexof的用法
- 请教 indexOF的用法
- ArrayList的indexOf用法
- js indexOf的用法
- String.indexof()的用法
- indexOf的用法
- IndexOf的用法
- indexOf的用法
- indexof(str)的用法
- javascript的indexOf的用法
- IndexOf、LastIndexOf、Substring的用法
- IndexOf、LastIndexOf、Substring的用法
- IndexOf、LastIndexOf、Substring的用法
- JAVA中indexOf的用法
- IndexOf、LastIndexOf、Substring的用法
- Java indexOf()的两个用法
- IndexOf、LastIndexOf、Substring的用法
- indexOf跟substring的用法
- HashMap源码分析(基于JDK1.6)
- java-基础-多态实现剖析
- 跟我学Redis(3)—Linux安装Redis
- 鼠标滑过链接雪碧图滑动
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- IndexOf的用法
- Timer vs TimerTask
- GZIP压缩原理分析(07)——第四章 基于gzip的HTTP压缩详解(四01) 章前语
- 面向对象和面向过程的区别
- Android图片缓存之Glide进阶(四)
- 【杭电oj1181】变形课
- Python字符串替换
- beego环境无脑搭建
- 跟我学Redis(4)—Redis配置文件redis.conf