AlgoBox { public static String first_N_Char_EW(String sInput, int nb) { if (sInput == null || "".equals(sInput)) { return ""; } StringBuilder sb = new StringBuilder(); StringTokenizer tok = new StringTokenizer(sInput); while (tok.hasMoreTokens()) { String word = tok.nextToken(); int wordCount = word.codePointCount(0, word.length()); for (int i = 0; i < nb && i < wordCount; i++) { int startOffset = word.offsetByCodePoints(0, i); String substring = word.substring(startOffset, word.offsetByCodePoints(startOffset, 1)); sb.append(substring); } } return sb.toString(); }  static void main(String[] args); static String pick_Char(String sInput, String pattern); static String first_N_Consonants(String sInput, int nb); static String first_N_Vowels(String sInput, int nb); static String subStr(String sInput, String pattern); static String first_N_Char(String sInput, int nb); static String last_N_Char(String sInput, int nb); static String first_N_Char_EW(String sInput, int nb); static String first_Char_EW(String sInput); static String soundex(String sInput); static String doublemetaphone(String sInput); static String metaphone(String sInput); static String add_Left_Char(String sInput, String position); static String add_Right_Char(String sInput, String position); static String removeDiacriticalMarks(String sInput); static String exact(String sInput); static String useDefault(String sInput, String insteadOf); static String lowerCase(String sInput); static String upperCase(String sInput); static String removeDMAndLowerCase(String sInput); static String removeDMAndUpperCase(String sInput); static String fingerPrintKey(String sInput); static String nGramKey(String sInput); static String colognePhonetic(String sInput);  }
@Test public void testFirst_N_Char_EW() { assertEquals(BLANK_STR, AlgoBox.first_N_Char_EW(null, 1)); assertEquals(TEST_STR, AlgoBox.first_N_Char_EW(TEST_STR, 4)); assertEquals(TEST_STR, AlgoBox.first_N_Char_EW(TEST_STR, 5)); assertEquals("tt", AlgoBox.first_N_Char_EW("test\ntest", 1)); assertEquals("tete", AlgoBox.first_N_Char_EW("test\ttest", 2)); assertEquals("testes", AlgoBox.first_N_Char_EW("test\ftest", 3)); assertEquals("tete", AlgoBox.first_N_Char_EW("test test", 2)); assertEquals("testtest", AlgoBox.first_N_Char_EW("test\rtest", 4)); assertEquals(BLANK_STR, AlgoBox.first_N_Char_EW(BLANK_STR, 1)); assertEquals("n", AlgoBox.first_N_Char_EW(NULL_STR, 1)); assertEquals(QUO_STR, AlgoBox.first_N_Char_EW(QUO_STR, 1)); assertEquals("ab", AlgoBox.first_N_Char_EW(" abc", 2)); assertEquals("a", AlgoBox.first_N_Char_EW(" abc", 1)); assertEquals("拓科", AlgoBox.first_N_Char_EW("拓蓝\r科技", 1)); assertEquals("𠀀𠀐𠀑a", AlgoBox.first_N_Char_EW("𠀀𠀐我\t𠀑ab", 2)); assertEquals("リ", AlgoBox.first_N_Char_EW(JAPANESE1_STR, 1)); assertEquals("リン", AlgoBox.first_N_Char_EW(JAPANESE2_STR, 2)); assertEquals("リンを食べ", AlgoBox.first_N_Char_EW(JAPANESE3_STR, 2)); }