查找字符串最后一次出现的位置(java) |
您所在的位置:网站首页 › excel查找字符串最后一次出现的位置 › 查找字符串最后一次出现的位置(java) |
以下实例中我们通过字符串函数 strOrig.lastIndexOf(Stringname) 来查找子字符串 Stringname 在 strOrig 出现的位置: public class SearchlastString { public static void main(String[] args) { String strOrig = "Hello world ,Hello Runoob"; int lastIndex = strOrig.lastIndexOf("Runoob"); if(lastIndex == - 1){ System.out.println("没有找到字符串 Runoob"); }else{ System.out.println("Runoob 字符串最后出现的位置: "+ lastIndex); } } } 输出结果:Runoob 字符串最后出现的位置: 19public int lastIndexOf(int ch)//ch -- 字符 或 public int lastIndexOf(int ch, int fromIndex)//fromIndex -- 开始搜索的索引位置 或 public int lastIndexOf(String str)//str -- 要搜索的子字符串 或 public int lastIndexOf(String str, int fromIndex) 例子: public class Test { public static void main(String args[]) { String Str = new String(& |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |