/** * Finds the index of the first digit. * * @param str String to search for a digit. * @return -1 if not found otherwise the index. */ public static int indexOfDigit(final String str) { return indexOfDigit(str, 0); }
/** * Finds the index of the first digit. * * @param str * String to seach for a digit. * @return -1 if not found otherwise the index. */ public static int indexOfDigit(String str) { return indexOfDigit(str, 0); }
/** * Finds the index of the first digit. * * @param str String to search for a digit. * @return -1 if not found otherwise the index. */ public static int indexOfDigit(final String str) { return indexOfDigit(str, 0); }
/** * Return the string of digits from string. * * @param str Source string to search. * @param idx Start index from which to search. */ public static String subDigitString(final String str, final int idx) { String ret = null; final int sidx = indexOfDigit(str, idx); if (sidx != -1) { final int eidx = indexOfNonDigit(str, sidx); ret = (eidx == -1) ? str.substring(sidx) : str.substring(sidx, eidx); } return ret; }
/** * Return the string of digits from string. * * @param str Source string to search. * @param idx Start index from which to search. */ public static String subDigitString(final String str, final int idx) { String ret = null; final int sidx = indexOfDigit(str, idx); if (sidx != -1) { final int eidx = indexOfNonDigit(str, sidx); ret = (eidx == -1) ? str.substring(sidx) : str.substring(sidx, eidx); } return ret; }
/** * Return the string of digits from string. * * @param str * Source string to search. * @param idx * Start index from which to search. */ public static String subDigitString(String str, int idx) { String ret = null; int sidx = indexOfDigit(str, idx); if (sidx != -1) { int eidx = indexOfNonDigit(str, sidx); ret = (eidx == -1) ? str.substring(sidx) : str .substring(sidx, eidx); } return ret; }
/** */ @Test public void testIndexOfDigit() { int test = 0; final String TEST0 = null; final String TEST1 = "fsadlkjffj"; final String TEST2 = "abac2dafj"; final String TEST3 = "fa323jf4af"; test = StringUtil.indexOfDigit(TEST0); assertEquals(test, -1); test = StringUtil.indexOfDigit(TEST1); assertEquals(test, -1); test = StringUtil.indexOfDigit(TEST2); assertEquals(test, 4); test = StringUtil.indexOfDigit(TEST3); assertEquals(test, 2); }