博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java String.indexOf() 函数用法小结
阅读量:4678 次
发布时间:2019-06-09

本文共 709 字,大约阅读时间需要 2 分钟。

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

转载于:https://www.cnblogs.com/hqbhonker/p/3384450.html

你可能感兴趣的文章
C# 实现保留两位小数的方法
查看>>
web前端面试的自我介绍
查看>>
朴素贝叶斯算法的实例
查看>>
Immunity Debugger
查看>>
Redis学习(8)-redis其他特性
查看>>
Swift使用NSKeyedArchiver进行数据持久化保存的经验
查看>>
【大数据】HBase环境
查看>>
NABCD需求分析
查看>>
HDU5879(打表)
查看>>
jQuery正则:电话、身份证、邮箱简单校验
查看>>
SpringMvc笔记二
查看>>
C#编写Windows服务程序图文教程
查看>>
私有Pods封装个推SDK功能(解决方案)
查看>>
dubbo 限流之TpsLimitFilter
查看>>
java基础 -- 关键字static的用法
查看>>
Cmdlet开发与学习(三)
查看>>
python之面向对象进阶
查看>>
Java学习----集合函数
查看>>
Sublime Text配置Python开发利器
查看>>
updateFilter
查看>>