zoukankan      html  css  js  c++  java
  • 求字符串的大小的长度

          public class Work {

           /*
                   *  获取一个字符串中,另一个字符串出现的次数
                   *  思想:
                   *    1. indexOf到字符串中到第一次出现的索引
                   *    2. 找到的索引+被找字符串长度,截取字符串
                   *    3. 计数器++
                 */
                public static void main(String[] args) {

                String s="hellowrdhellowrdhellowrdhellowrdhellowrdhellowrd";     //定义字符串
                       function (s,"l");  //添加function方法

             }

            public  static void function(String s, String m) {  //调用function方法
                      int count=0;  定义 int类型的数量
                      while(s.indexOf(m)>=0){  //使while语句 定义查找字符或者子串第一次出现的地方从零开始
                          int  index=s.indexOf(m)+m.length();   //查找m的字符串和m字符串的长度
                          s=s.substring(index)        //  ;截取字符串
                          count++;              

            }
                        int q=s.length();      //字符串的长度


                System.out.println("出现的 索引 :"+count+"     字符串的长度:"+q);  //打印
            
        }

          }

  • 相关阅读:
    针对安卓java入门:方法的使用
    ES6里关于字符串的拓展
    ES6里关于数字的拓展
    项目笔记:导出XML和导出全部XML功能
    项目笔记:中文转拼音工具类
    深入理解dataset及其用法
    前端插件实现图片懒加载
    Java里日期转换及日期比较大小
    iframe.contentWindow 属性:关于contentWindow和contentDocument区分
    GROUP BY 和 GROUP_CONCAT的使用
  • 原文地址:https://www.cnblogs.com/hph1728390/p/10555584.html
Copyright © 2011-2022 走看看