zoukankan      html  css  js  c++  java
  • 查找字符串最后一次出现的位置

    package font_files;
    
    public class SearchLastString {
        public static void main(String[] args) {
           String randomword = "nice is good, and I like nicessss, do you like?";
           String love ="nice";
           int location = randomword.lastIndexOf(love);
           if (location==-1){
               System.out.println("Not find!");
           }else {
               System.out.println("randomword is located in " + location);
           }
        }
    }
    

    结果为:

    randomword is located in 25
    

    可以看出,这个lastIndexOf()函数只是找到相同的字符段就行了,不管是不是相同的单词。




    package font_files;
    
    public class SearchLastString {
        public static void main(String[] args) {
           String randomword = "nice is good, and I like neicessss, do you like?";
           String love ="nice";
           int location = randomword.lastIndexOf(love);
           if (location==-1){
               System.out.println("Not find!");
           }else {
               System.out.println("randomword is located in " + location);
           }
        }
    }
    

    结果为:

    randomword is located in 0
    
    

    这个查找是从0 开始的。

    热爱每一天
  • 相关阅读:
    js获取当前网址Url
    ajax解决跨域问题
    微信小程序传递URL中含有特殊字符
    layui中的tab切换
    layer.confirm等事件X关闭与取消监听
    Java中的API方法总结
    sublime安装插件
    LNMP的基本配置
    LNMP环境的搭建
    LAMP安装细则
  • 原文地址:https://www.cnblogs.com/blueblog6/p/15202816.html
Copyright © 2011-2022 走看看