以前的做分隔符獲取一個(gè)個(gè)字符串很是麻煩,其實(shí)JDK中的String 類已經(jīng)很好的解決了這個(gè)問題。正則表達(dá)式確實(shí)是個(gè)好東西!
split
public String[] split(String regex)
- Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument
split
method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.The string "boo:and:foo", for example, yields the following results with these expressions:
Regex Result : { "boo", "and", "foo" } o { "b", "", ":and:f" } - Parameters:
regex
- the delimiting regular expression- Returns:
- the array of strings computed by splitting this string around matches of the given regular expression
- Throws:
PatternSyntaxException
- if the regular expression's syntax is invalid- Since:
- 1.4
- See Also:
Pattern