String 类有以下方法:
startsWith(String prefix)
Tests if this string starts with the specified prefix.
- Parameters:
- prefix the prefix.
- Returns:
-
true
if the character sequence represented by the argument is a prefix of the character sequence represented by this string;false
otherwise. Note also thattrue
will be returned if the argument is an empty string or is equal to thisString
object as determined by theequals(Object)
method. - Since:
- 1. 0
- 就是判断字符串中的后缀是否为参数prefix,如果是就返回true,如果不是就返回false。
- 这在安卓中可以用来识别音频文件,如mp3文件等。
- 对应的,还有一个方法,
- endsWith(String suffix)
-
Tests if this string ends with the specified suffix.
- Parameters:
- suffix the suffix.
- Returns:
-
true
if the character sequence represented by the argument is a
suffix of the character sequence represented by this object;false
otherwise. Note that the result will betrue
if the argument is the
empty string or is equal to thisString
object as determined by theequals(Object)
method. - 可以用来判断一个字符串是否以suffix这个参数开头。