• 求字符串的大小的长度


          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);  //打印
            
        }

          }

  • 相关阅读:
    linux下压力测试工具ab的使用
    linux下nginx日常操作
    centos7编译安装nginx
    ssh登录locale报错:cannot change locale (zh_CN.UTF-8): No such file or directory
    linux重装rabbitmq的问题
    rabbitmq3.6.5镜像集群搭建以及haproxy负载均衡
    linux安装rabbitmq3.6.5
    centos6升级glibc-2.14没有报错,但是验证没有升级成功的问题解决
    linux卸载erlang
    asp web服务
  • 原文地址:https://www.cnblogs.com/hph1728390/p/10555584.html
Copyright © 2020-2023  润新知