查找字符串最后一次出现的位置

时间:2019-09-20 00:31:08   收藏:0   阅读:102

以下实例中我们通过字符串函数 strOrig.lastIndexOf(Stringname) 来查找子字符串 Stringname 在 strOrig 出现的位置:

也可以从前向后遍历数据,判断里面strOrig[i]=="Runoob",i++;

String strOrig = "Hello world ,Hello Runoob";

int lastIndex = strOrig.lastIndexOf("Runoob").;

if(lastIndex == - 1)

{

System.out.println("没有找到字符串 Runoob"); }

else

{

System.out.println("Runoob 字符串最后出现的位置: "+ lastIndex);

}

原文:https://www.cnblogs.com/onetheway2018/p/11553016.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!