Android Utililty Methods String Trim

List of utility methods to do String Trim


The list of methods to do String Trim are organized into topic(s).


StringtrimStart(String s)
Trim characters from only the beginning of a string.
return trimStart(s, null);
Stringtrim(String str)
return str == null ? null : str.trim();
StringtrimToNull(String str)
trim To Null
return isBlank(str) ? null : trim(str);
String[]splitAndTrim(String str, String delims)
split And Trim
return split(str, delims, true);
StringtrimEnd(String s)
Trim characters from only the end of a string.
return trimEnd(s, null);
StringnullsafeTrim(String str)
nullsafe Trim
return TextUtils.isEmpty(str) ? str : str.trim();
StringtrimScheme(String uri)
trim Scheme
if (uri.regionMatches(0, ContentResolver.SCHEME_FILE, 0,
        sFileSchemeLength)) {
    return uri.substring(sFileSchemeLength + sSuffixLength);
} else if (uri.regionMatches(0, ContentResolver.SCHEME_CONTENT, 0,
        sContentSchemeLength)) {
    return uri.substring(sContentSchemeLength + sSuffixLength);
return uri;
Stringltrim(final String text)
return ltrim(text, null);
Stringltrim(final String text, String trimText)
if (text == null) {
    return null;
if (trimText == null) {
    trimText = " ";
int pos = 0;
for (; pos < text.length(); pos++) {
Stringrtrim(final String text)
return rtrim(text, null);