/** * Finds the index of the first non digit. * * @param str String to search for a non digit. * @return -1 if not found otherwise the index. */ public static int indexOfNonDigit(final String str) { return indexOfNonDigit(str, 0); }
/** * Finds the index of the first non digit. * * @param str * String to seach for a non digit. * @return -1 if not found otherwise the index. */ public static int indexOfNonDigit(String str) { return indexOfNonDigit(str, 0); }
/** * Finds the index of the first non digit. * * @param str String to search for a non digit. * @return -1 if not found otherwise the index. */ public static int indexOfNonDigit(final String str) { return indexOfNonDigit(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 testIndexOfNonDigit() { int test = 0; final String TEST0 = null; final String TEST1 = "2131398750976"; final String TEST2 = "21312a9320484"; final String TEST3 = "32323aa323435"; test = StringUtil.indexOfNonDigit(TEST0); assertEquals(test, -1); test = StringUtil.indexOfNonDigit(TEST1); assertEquals(test, -1); test = StringUtil.indexOfNonDigit(TEST2); assertEquals(test, 5); test = StringUtil.indexOfNonDigit(TEST3); assertEquals(test, 5); }