Here you can find the source of substringByMask(String baseString, String baseMask, String subMask)
public static final String substringByMask(String baseString, String baseMask, String subMask)
//package com.java2s; /**//from w w w . j av a 2 s . co m * Converts a line of text into an array of lower case words using a * BreakIterator.wordInstance(). * <p> * * This method is under the Jive Open Source Software License and was * written by Mark Imbriaco. * * @param text * a String of text to convert into an array of words * @return text broken up into an array of words. */ public class Main { public static final String substringByMask(String baseString, String baseMask, String subMask) { if ((baseString == null) || (baseMask == null) || (subMask == null)) { return null; } else if (isEmpty(baseString)) return baseString; else { String ls_Return = ""; int li_Pos = 0; while (li_Pos >= 0) { li_Pos = baseMask.indexOf(subMask, li_Pos); if (li_Pos >= 0) { ls_Return += baseString.substring(li_Pos, li_Pos + subMask.length()); li_Pos += subMask.length(); } } return ls_Return; } } public static final boolean isEmpty(String baseString) { return isEmpty((Object) baseString); } public static final boolean isEmpty(Object baseObject) { if (baseObject == null) return true; else if (baseObject instanceof String) return ((String) baseObject).equals(""); else return false; } public static final int indexOf(String baseString, String indexString) { return indexOf(baseString, indexString, 0); } public static final int indexOf(String baseString, String indexString, int index) { if (baseString == null) return -1; else return baseString.indexOf(indexString, index); } public static int indexOf(String baseString, String indexString, int index, int repeat) { if (baseString == null || indexString == null) return -1; else { int li_PosOfStart = index; int li_Repeat = 0; int li_Times = 0; while (li_PosOfStart >= 0) { li_Times++; if (li_Times > 1000) { return -1; } li_PosOfStart = baseString.indexOf(indexString, li_PosOfStart); li_Repeat++; if (li_PosOfStart >= 0 && startsWith(substring(baseString, li_PosOfStart + indexString.length()), indexString)) li_PosOfStart += indexString.length(); else { if (li_Repeat == repeat) { break; } else { li_Repeat = 0; li_PosOfStart++; } } } return li_PosOfStart; } } public static final String substring(String baseString, int start, int end) { if (baseString == null) return null; else if (start >= baseString.length() || start < 0 || end < 0 || start > end) return null; else if (end >= baseString.length()) return baseString.substring(start); else { return baseString.substring(start, end); } } public static final String substring(String baseString, int start) { if (baseString == null) return null; else return substring(baseString, start, baseString.length()); } public static final int length(String baseString) { if (baseString == null) return 0; else return baseString.length(); } public static final boolean equals(String baseString, Object param1) { if (baseString == null) { if (param1 == null) return true; else return false; } else return baseString.equals(param1); } /** * startWith */ public static boolean startsWith(String baseString, String compareString) { if (baseString == null || compareString == null) return false; else return baseString.startsWith(compareString); } }