indexOf与substring
来源:互联网 发布:js给元素赋值 编辑:程序博客网 时间:2024/04/28 19:05
简述:
1.indexOf(String str) : 返回str第一次出现的位置-1,如果不存在返回-1;
2.indexOf(String str,int i) : 返回 从第i个位置开始查找,出现str的位置-1,同样,不存在返回-1;
3.substring(int startPosition , int endPosition):返回在startPosition和endPosition位置之间的字符串,不包括前面端点,包含后面端点。
4.substring(int pisition) :返回从这个位置开始,一直到结束的字符串。
测试源码如下:
public static void main(String[] args) { String str = "url:'www.baidu.com'"; int index = str.indexOf("url"); //注意:结果是url第一次出现的位置-1,结果:0 System.out.println(index); int index2 = index + "url:'".length(); System.out.println(index2); int index3 = str.indexOf("'",index2); //从index2这个位置开始查找,(不含第5个位置)出现“‘”的位置,仍是所在位置-1,结果:18. System.out.println(index3); //截取index2和index3之间的字符串,不含前边界,含后边界的。 String urlString = str.substring(index2, index3); System.out.println(urlString); }
0 0
- indexOf与substring
- IndexOf与substring的使用
- indexOf() substring()
- String类中IndexOf与SubString
- Java substring()与indexOf()方法使用注意
- 转:c#中indexof与substring的区别
- indexOf,substring,substr(Javascript)
- IndexOf()和Substring()方法
- substring indexof split replace
- substring 和IndexOf
- Java---IndexOf、LastIndexOf、Substring
- js indexOf substring用法
- toString.indexOf(":")和subsTring
- C#(IndexOf、LastIndexOf、Substring)
- java substring and indexOf 方法
- IndexOf、LastIndexOf、Substring的用法
- IndexOf、LastIndexOf、Substring的用法
- substr,substring,indexOf,lastIndexOf用法
- Qt 中 Label 显示OpenCV 图像(IplImage*)
- RAW格式
- emulator: ERROR: x86 emulation currently requires hardware acceleration!
- java project 项目在 linux 下面部署步骤
- [Unity实战]一个简单的任务系统(一)
- indexOf与substring
- 日语方位词
- 硬木地板
- JDBC连接mySQL数据库
- 上架AppStore 遇到的问题总结
- Android Bundle详解
- Xunsearch体验Demo
- PyCharm个性化设置及注意事项
- C warning: function declaration isn’t a prototype