String.indexOf函数用法小结

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值