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
  • 相关阅读:
    centos mongo数据库搭建
    闪屏页白屏或者显示旧图
    在Sqlserver下巧用行列转换日期的数据统计
    读 《.Net 之美》解析.Net Remoting (应用程序域)-- Part.1
    MVC的自定义动作过滤器(一)
    【算法】快排
    【编程范式】C语言1
    排序
    日志记录类
    邮箱发送类
  • 原文地址:https://www.cnblogs.com/xiarongjin/p/8309673.html
Copyright © 2011-2022 走看看