字符串的截取

根据开始和结束位置截取字符串:

public String substring(int beginIndex):

    "unhappy".substring(2) returns "happy"

    "Harbison".substring(3) returns "bison"

    "emptiness".substring(9) returns "" (an empty string)

public String substring(int beginIndex, int endIndex):

    "hamburger".substring(4, 8) returns "urge"

     "smiles".substring(1, 5) returns "mile"

根据正则表达式截取字符串,返回的可能是字符串数组:

public String[] split(String regex)

Regex结果
: { "boo", "and", "foo" }
o { "b", "", ":and:f" }

 

String str[]="boo:and:foo".split(":");
String str[]="boo:and:foo".split("o");

 

posted @ 2020-06-19 15:28  云山有相逢  阅读(161)  评论(0)    收藏  举报