* @author gyeongseok.seo@samsung.com, S-Core Inc.
* <ul>
* <li> added split method.
+ * <li> added removeStart method.
* </ul>
*/
public class StringUtil
return str;
}
+ /**
+ * remove string in target string
+ * if target is empty or remove word is empty then just return target string
+ *
+ * @param str - target string
+ * @param remove - remove string
+ * @return removed target string
+ */
+ public static String removeStart(String str, String remove) {
+ if (isEmpty(str) || isEmpty(remove) ) {
+ return str;
+ }
+ if (str.startsWith(remove)){
+ return str.substring(remove.length());
+ }
+ return str;
+ }
+
/* Logging */
/**
* </p>
assertEquals(enumBuilder.toString(), utilBuilder.toString());
}
+ /**
+ * Test {@link StringUtil#removeStart(String, String)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see {@link StringUtil#removeStart(String, String)}
+ */
+ @Test
+ public void
+ test_removeStart()
+ throws Exception
+ {
+ String str = "abcdefg";
+ String remove1 = "a";
+ String remove2 = "abc";
+ String remove3 = "def";
+
+ // null test
+ assertEquals( str, StringUtil.removeStart( str, null ) );
+ assertEquals( null, StringUtil.removeStart( null, remove1 ) );
+ assertEquals( null, StringUtil.removeStart( null, null ) );
+
+ // start with
+ assertEquals( "bcdefg", StringUtil.removeStart(str, remove1 ) );
+ assertEquals( "defg", StringUtil.removeStart(str, remove2 ) );
+
+ // not start with
+ assertEquals( str, StringUtil.removeStart(str, remove3 ) );
+ }
+
public enum TestEnumCase {
ABC("ABC"),
DEF("DEF"),