Android String Sub String Get substringBefore(String text, char separator)

Here you can find the source of substringBefore(String text, char separator)

Description

Gives the substring of the given text before the given separator.

Declaration

public static String substringBefore(String text, char separator) 

Method Source Code

//package com.java2s;
import android.text.TextUtils;

public class Main {
    /**//w  ww. j av  a2  s  . c om
     * Gives the substring of the given text before the given separator.
     */
    public static String substringBefore(String text, char separator) {
        if (isEmpty(text))
            return text;
        int sepPos = text.indexOf(separator);
        if (sepPos < 0)
            return text;
        return text.substring(0, sepPos);
    }

    /**
     * Whether the given string is null or zero-length
     */
    public static boolean isEmpty(String text) {
        return TextUtils.isEmpty(text);
    }
}

Related

  1. substringToLast(final String str, final String separator)
  2. takeOutFirstChar(String input)
  3. substring(String str, int srcPos, int specialCharsLength)
  4. substringAfter(String text, char c)
  5. substringAfterLast(String text, char separator)
  6. substringBefore(String text, char separator)
  7. substringBeforeLast(String text, char separator)