首页 > Java基础 > string 类常用方法 操作字符串
2018
06-05

string 类常用方法 操作字符串

public boolean isEmpty()  //判断字符串是否为空
public int length()       //获取字符串长度
public string substring(int beginIndex)//取子字符串
public string substring(int beginIndex,int endIndex) //取子字符串
public int indexOf(int ch) //查找字符。返回第一个找的索引位置,没有找到返回-1
public int indexOf(string str) //查找字串,返回第一个找到的索引位置,没有找到返回-1
public int lastIndexOf(int ch) //从后面查找字符串
public boolean contains(CharSequence s) //判断字符串中是否包含指定的字符序列
public boolean startsWith(string prefix)//判断字符串是否 以子字符串开头
public boolean equals(Object anObject) //与其他字符串比较,看内容是否相同
public boolean equalsIgnoreCase(string anotherSring) //忽略大小写是否相同
public string toUpperCase()//所有字符转换为大写字符,返回新字符串,原字符串不变
public string toLowerCase () //所有字符转换为小写字符,返回新字符串,原字符串不变
public srting concat(string str) //字符串连接,返回当前字符串和参数字符串合并的结果
public string replace(char oldChar,char newChar) //字符串替换,替换单个字符串
public string replace(charSequence target,charSequence replacement)  //字符串替换,替换字符序列,返回新的字符串,原字符串不变
public string trim() //删掉开头和结尾的空格,返回新字符串,原字符串不变
public srting[] split(string regex) //分隔字符串,返回分隔后的子字符串数组


本文》有 0 条评论

留下一个回复