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

以下实例中我们通过字符串函数 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);

}

posted on 2019-09-19 22:26  每天在路上2018  阅读(4045)  评论(0编辑  收藏  举报