您的位置 首页 java

超实用 Java中String类常用方法2 知道的越多编程越溜 有例子

关注小编,可以天天看新内容哦

public int indexOf(String str)

使用方式同上。查找的是 字符串 第一次出现的 索引

public int indexOf(String str,int fromIndex)

使用方式同上。从字符串索引fromIndex处向后查找,查找的是字符串第一次出现的索引。

public int lastIndexOf(int ch)、public int lastIndexOf(String str)

返回指定字符或字符串在此字符串中最后一次出现处的索引。

public int lastIndexOf(int ch,int fromIndex)、public int lastIndexOf(String str,int fromIndex)

从指定的索引开始反向搜索查找,查找字符或字符串在此字符串中最后一次出现处的索引。

public boolean regionMatches(int toffset,String other,int ooffset, int len)

测试两个字符串的区域字符串是否相等。

public boolean regionMatches(boolean case,int toffset,String other,int ooffset, int len)

测试两个字符串的区域字符串是否相等,当case为true时,忽略大小写。

public String replace(char oldChar, char newChar)

使用字符newChar替换字符串中出现的所有的oldChar并返回一个新的字符串。

public String replace(String oldStr, String newStr)

使用字符串替换原字符串中所有oldChar,并返回新的字符串。

public String replaceFirst (String oldStr, String newStr)

使用字符串newStr替换第一次出现的oldStr子串。

public String[] split(String regex)

根据给定的分隔符对字符串进行拆分,返回一个字符串数组。

public boolean startsWith(String prefix)

判断字符串是否以指定的前缀开始,如果是返回true,否则返回 false

public boolean startsWith(String prefix, int toffset)

判断字符串从指定偏移量开始的子字符串是否以指定前缀开始。如果是返回true,否则返回false。

public String substring(int beginIndex)

返回一个新的字符串,从指定索引处的字符开始截取,直到字符串末尾。

public String substring(int beginIndex, int endIndex)

返回一个新字符串,从指定的索引处开始截取,直到索引为endIndex – 1处的字符。

如果您觉得文章还可以,请关注小编,还可以天天看新内容哦

文章来源:智云一二三科技

文章标题:超实用 Java中String类常用方法2 知道的越多编程越溜 有例子

文章地址:https://www.zhihuclub.com/183830.shtml

关于作者: 智云科技

热门文章

发表回复

您的电子邮箱地址不会被公开。

网站地图