src/main/java/com/findupon/commons/utilities/NumUtils.java
/**
	 * Takes in a String formatted as 2137 km (1328 mi) and returns 1328.
	 *
	 * @param str
	 * @return
	 */
Takes in a String formatted as 2137 km (1328 mi) and returns 1328.
@param str
@return
Takes in a String formatted as 2137 km ( 1328 mi ) and returns 1328 . @param str @return
public static int fromMileageString(String str) {
		int errorCode = hasErrors(str);
		if(errorCode != NONE) {
			return errorCode;
		}
		for(String word : wordRemovalDictionary) {
			str = StringUtils.remove(str, word);
		}
		if(str.contains("(")) {
			str = StringUtils.substringAfter(str, "(");
			str = StringUtils.substringBefore(str, " mi");
		}
		if(StringUtils.endsWith(str, "K") || StringUtils.endsWith(str, "k")) {
			str = StringUtils.replace(str, "K", "000");
			str = StringUtils.replace(str, "k", "000");
		}
		if(NumberUtils.isDigits(str)) {
			return Integer.valueOf(
					StringUtils.defaultString(
							StringUtils.trimToEmpty(str),
							"-1"));
		} else {
			return -1;
		}
	}
public static int fromMileageString ( String str ) { int errorCode = hasErrors ( str ) ; if ( errorCode != NONE ) { return errorCode ; } for ( String word : wordRemovalDictionary ) { str = StringUtils . remove ( str , word ) ; } if ( str . contains ( "(" ) ) { str = StringUtils . substringAfter ( str , "(" ) ; str = StringUtils . substringBefore ( str , " mi" ) ; } if ( StringUtils . endsWith ( str , "K" ) || StringUtils . endsWith ( str , "k" ) ) { str = StringUtils . replace ( str , "K" , "000" ) ; str = StringUtils . replace ( str , "k" , "000" ) ; } if ( NumberUtils . isDigits ( str ) ) { return Integer . valueOf ( StringUtils . defaultString ( StringUtils . trimToEmpty ( str ) , "-1" ) ) ; } else { return - 1 ; } }
Takes in a String formatted as 2137 km (1328 mi) and returns 1328.
Takes in a String formatted as 2137 km ( 1328 mi ) and returns 1328 .
// Dupont Registry Bot // James Edition Bot // CarmaxAutomobile