java中substring和indexof() 和lastindexof()
2024-10-19 08:45:53
java中substring和indexof() 和lastindexof()
str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字符串,将剩余字符串赋值给str;
str=str.substring(int beginIndex,int endIndex);截取str中从beginIndex开始至endIndex结束时的字符串,并将其赋值给str;
indexOf
public int indexOf(Object o, int index)
返回此向量中第一次出现的指定元素的索引,从 index
处正向搜索,如果未找到该元素,则返回 -1。
lastIndexOf
public int lastIndexOf(Object o)
返回此向量中最后一次出现的指定元素的索引;如果此向量不包含该元素,则返回 -1。
以下是一段演示程序:
public class Test{
public static void main(String agrs[]){
String str="tao.jpg";
System.out.println("点的索引:"+str.lastIndexOf("."));
str=str.substring(str.lastIndexOf("."));
System.out.println("陶相山陶相山陶相山:"+str);
}}
运行结果是:点的索引:3
陶相山陶相山陶相山:.jpg
最新文章
- LeetCode:Word Ladder I II
- 认识基本的mfc控件
- md5的C++实现
- SimpleDateFormate的使用
- win2008主机IIS7.x 关于web.config设置301重定向
- bootstrap学习笔记<;七>;(图标,图像)
- 【转】如何使用PhoneGap打包Web App
- notebook笔记
- Umbraco(7)-The Navigation Menu And A Parent Page with Infinite Children
- posix thread条件变量
- Git-it:一个学习Git和Github的教程(软件)
- Yii PHP 框架分析(二)
- ERROR: The node /hbase is not in ZooKeeper. It should have been written by the master. Check the value configured in &#39;zookeeper.znode.parent&#39;. There could be a mismatch with the one configured in the
- angr进阶(5)内存操作
- Html5: Drawing with text
- python 分享一个通过 (key1.key2.key3) 形式获取嵌套字典值的方法
- DEM山体阴影原理以及算法具体解释
- freeswitch 获取当前网关通道数
- CXF develop Webserice Tuturial
- Android控件第3类——AdapterView