zoukankan      html  css  js  c++  java
  • String 类 常用函数

    构造方法摘要:

    String(byte[] bytes) 
              通过使用平台的默认字符集解码指定的 byte 数组,构造一个新的 String
    String(char[] value) 
              分配一个新的 String,使其表示字符数组参数中当前包含的字符序列。
     
    方法摘要:
     
    char charAt(int index) 
              返回指定索引处的 char 值。
    String concat(String str) 
              将指定字符串连接到此字符串的结尾。
    boolean endsWith(String suffix) 
              测试此字符串是否以指定的后缀结束。
     int indexOf(int ch) 
              返回指定字符在此字符串中第一次出现处的索引。
    int    indexOf(String str, int fromIndex) 
              返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
    boolean isEmpty() 
              当且仅当 length() 为 0 时返回 true
    int lastIndexOf(int ch) 
              返回指定字符在此字符串中最后一次出现处的索引。
    int lastIndexOf(String str, int fromIndex) 
              返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索。
    boolean matches(String regex) 
              告知此字符串是否匹配给定的正则表达式
    String replace(char oldChar, char newChar) 
              返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
    String replaceAll(String regex, String replacement) 
              使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。
    String[] split(String regex, int limit) 
              根据匹配给定的正则表达式来拆分此字符串。
    boolean startsWith(String prefix, int toffset) 
              测试此字符串从指定索引开始的子字符串是否以指定前缀开始。
    String substring(int beginIndex, int endIndex)    //包含beginIndex,但是不包含endIndex
              返回一个新字符串,它是此字符串的一个子字符串。
     char[] toCharArray() 
              将此字符串转换为一个新的字符数组。
     String trim() 
              返回字符串的副本,忽略前导空白和尾部空白。
    static String valueOf(char[] data) 
              返回 char 数组参数的字符串表示形式。
     

    boolean contains(CharSequence s) 
              当且仅当此字符串包含指定的 char 值序列时,返回 true。
    String s = "dgersddaaasser";        System.out.println(s.contains("da"));    //true
  • 相关阅读:
    CSS常用记录
    CSS字体图标使用方式
    CSS之多个div一行排列
    Mysql MVCC原理和幻读解决
    第8章 管理还原数据
    第20章 数据的移动
    oracle恢复删除的数据
    第11章 索引的管理与维护
    第10章 管理表
    第19章 归档模式下的数据库恢复
  • 原文地址:https://www.cnblogs.com/xiarongjin/p/8309673.html
Copyright © 2011-2022 走看看