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 开始的。

    热爱每一天
  • 相关阅读:
    Matlab---绘制柱状图
    认识Caffe与Caffe2
    Matlab---绘图及其位置摆放
    Matlab---三维视图的自动旋转
    Matlab---读取 .txt文件
    Matlab---画图线型、符号及颜色
    day 28 黏包及黏包解决方案
    day 27
    day 26 网络知识 01
    day 25 模块与包
  • 原文地址:https://www.cnblogs.com/blueblog6/p/15202816.html
Copyright © 2011-2022 走看看