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)
     }
    }

  • 相关阅读:
    Pycharm中安装第三方库
    Cookie&Session区别
    在线AES加解密
    Python_base_正则表达式
    POST四种常见的传参区别
    SQL基础语法与规则
    SQL的4种连接
    Python_base_Log
    <11>Golang基础进阶——指针
    Shell脚本——特殊变量
  • 原文地址:https://www.cnblogs.com/rong123/p/9894437.html
Copyright © 2011-2022 走看看