Here you can find the source of substringBefore(String str, int endChar)
public static String substringBefore(String str, int endChar)
//package com.java2s; /*!/* www . j a va 2 s . c o m*/ * mifmi-commons4j * https://github.com/mifmi/mifmi-commons4j * * Copyright (c) 2015 mifmi.org and other contributors * Released under the MIT license * https://opensource.org/licenses/MIT */ public class Main { public static String substringBefore(String str, int endChar) { if (str == null) { return null; } if (endChar < 0) { return str; } int idx = str.indexOf(endChar); if (idx == -1) { return str; } return str.substring(0, idx); } public static String substringBefore(String str, String endStr) { if (str == null) { return null; } if (endStr == null) { return str; } int idx = str.indexOf(endStr); if (idx == -1) { return str; } return str.substring(0, idx); } public static int indexOf(CharSequence charSeq, char ch) { return indexOf(charSeq, ch, 0); } public static int indexOf(CharSequence charSeq, char ch, int fromIndex) { if (charSeq == null) { return -1; } int len = charSeq.length(); for (int i = fromIndex; i < len; i++) { char c = charSeq.charAt(i); if (c == ch) { return i; } } return -1; } public static int indexOf(CharSequence charSeq, char[] ch) { return indexOf(charSeq, ch, 0); } public static int indexOf(CharSequence charSeq, char[] ch, int fromIndex) { if (charSeq == null) { return -1; } int len = charSeq.length(); for (int i = fromIndex; i < len; i++) { char c = charSeq.charAt(i); for (int j = 0; j < ch.length; j++) { if (c == ch[j]) { return i; } } } return -1; } }