String.indexOf函数用法小结
2013-05-07 16:26
453 查看
http://ilcy2000.blog.sohu.com/69057973.html部分转载于此,多谢原作者!
——————————————————————————————————————————————————————————————————————String.indexOf函数用法小结
1. indexOf的参数是String, startIndex: Number; indexOf的返回值为int,
2. Function indexOf 包含如下几个格式:
1). Strng.indexOf(substring) //搜索String中的substring,默认从0位开始;
2). String.indexOf(substring, int m) //搜索String中的substring, 默认从第m位开始;
Sample:
取IP地址的第一个代码段:
int p;
int q;
String inputIP = null;
String IPsection1 = null;
String IPsection2 = null;
inputIP = "1.100.1.1";
p = inputIP.indexOf('.');
q = inputIP.indexOf('.',p+1);
IPsection1 = inputIP.substring(0,p);
IPsection2 = inputIP.substring(p+1, q);
System.out.println("the 1st IP section is "+IPsection1);
System.out.println("the 2nd IP section is "+IPsection2);
输出结果为
the 1st IP section is 1
the 2nd IP section is 100
相关文章推荐
- python_string常用函数用法小结
- Java String.indexOf() 函数用法小结
- C#中indexof和substring函数用法
- C#中indexof和substring函数用法 (收集)
- c++中的string常用函数用法总结
- Redis系列-存储篇string主要操作函数小结
- Java String.split()用法小结
- java String.split()函数的用法分析
- c++中string的用法小结
- Java String.split()用法小结
- Java String.split()用法小结
- string里的IndexOf、LastIndexOf、Substring的详解(意义和用法)
- Java String.split()用法小结
- 深入C++ string.find()函数的用法总结
- 牛人总结python中string模块各属性以及函数的用法,果断转了,好东西
- Java 中 String的indexOf 的用法
- C++中的string常用函数用法总结
- linux下 select() 函数的用法小结
- Java String.split()用法小结
- JAVA中indexOf函数用法