zoukankan      html  css  js  c++  java
  • StringDemo1

    package cn.zuoye;
    /*
     * string 类的获取功能
     * int length()获取字符串长度
     * char charAt(int index)获取指定索引位置的字符
     * 这里用int类型,因为97也等于a
     * int indexOf(int ch)返回指定 字符 在此字符串中第一次出现处的索引
     * int indexOf(string str)返回指定 字符串 在此字符串中第一次出现处的索引
     * int indexOf(int ch,int fromIndex)返回指定 字符 在此字符串中从指定位置后第一次出现处的索引
     * int indexOf(string str,int fromIndex)返回指定 字符串 在此字符串中从指定位置后第一次出现处的索引
     * string substring(int start) 从指定位置开始截取字符串,默认到结尾
     * string substring(int start,int end)从指定位置开始到指定位置结束 截取字符串
     */
    public class StringDemo1 {
     public static void main(String[] args) {
      //定义一个字符串对象
      String s = "helloworld";
      //int length()获取字符串长度
      System.out.println("s.length:"+s.length());
     
      //char charAt(int index)获取指定索引位置的字符
      System.out.println("charAt:"+s.charAt(5));
      
      //int indexOf(int ch)返回指定 字符 在此字符串中第一次出现处的索引
      System.out.println("indexOf:"+s.indexOf('l'));
      
      //int indexOf(string str)
      System.out.println("indexOf:"+s.indexOf("lo"));
      
      //int indexOf(int ch,int fromIndex)
      System.out.println("indexOf:"+s.indexOf('l',2));
      
      //string substring(int start)
      System.out.println("subString:"+s.substring(5));
      
      //string substring(int start,int end)
      System.out.println("substring:"+s.substring(3,9));//[3,9)
     }
    }

  • 相关阅读:
    DNF(一.YUM已死,DNF代之)
    cmd中运行python文件,并带参数
    python中dict[key] 存在key,但是报错:KeyError
    回测指标计算
    python进行excel操作
    myquant平台搭建及使用
    远程连接mongodb时,27017端口连接不上的解决办法
    python---urllib模块
    python---socket模块
    状态模式
  • 原文地址:https://www.cnblogs.com/rong123/p/9894437.html
Copyright © 2011-2022 走看看