List of usage examples for java.lang Character isDigit
public static boolean isDigit(int codePoint)
From source file:Main.java
/** * Remove none digital character from the decimal string that maybe contains * none digit character./* w w w . j a v a 2 s. c om*/ * * @param decimal * the decimal string. * @return the new digital string only contains digital character. */ public static String getPlain(String decimal) { if (TextUtils.isEmpty(decimal)) { decimal = "0"; } char[] ch = new char[decimal.length()]; int index = 0; for (int i = 0; i < decimal.length(); i++) { if (Character.isDigit(decimal.charAt(i))) { ch[index++] = decimal.charAt(i); } } return String.copyValueOf(ch, 0, index); }
From source file:Main.java
public static boolean isAddress(String address) { int i = 0, j = 0, k = 0, u = 0; int count = address.length(); Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]"); Matcher m = pattern.matcher(address); while (m.find()) { i++;/*from w w w .j a va 2s . c o m*/ } for (int idx = 0; idx < count; idx++) { char c = address.charAt(idx); int tmp = (int) c; if ((tmp >= 'a' && tmp <= 'z') || (tmp >= 'A' && tmp <= 'Z')) { j++; } if (Character.isDigit(address.charAt(idx))) { k++; } if (c == ' ') { u++; } } if ((i + j + k + u) == count) { return true; } else { return false; } }
From source file:Main.java
public static boolean IsNumeric(String number) { for (int i = 0; i < number.length(); i++) { if (!Character.isDigit(number.charAt(i))) return false; }/*from ww w . j a v a 2 s.c om*/ return true; }
From source file:Main.java
public static int searchChar(String str) { char[] c = str.toCharArray(); int i = 0;//from w w w. j a va2s. c o m for (i = 0; i < c.length; i++) { if (!Character.isDigit(c[i])) return i; } return 0; }
From source file:edu.illinois.cs.cogcomp.ner.StringStatisticsUtils.MyString.java
public static String cleanPunctuation(String s) { StringBuilder res = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isLetter(c) || Character.isDigit(c)) res.append(c);//from w w w . j a va 2 s .co m } return res.toString(); }
From source file:Main.java
public static int getAddressTypeFor(String address) { boolean international = false; // strip any + to simplify checks // but presence of + automatically assumes an // international style address if (address.startsWith("+")) { international = true;//from w w w . j a v a 2s.co m address = address.substring(1); } for (int i = 0; i < address.length(); i++) { if (!Character.isDigit(address.charAt(i))) { // check if alphanumeric return createAddressType(ADDRESS_TYPE_ALPHANUMERIC); } } if (international) { return createAddressType(ADDRESS_TYPE_INTERNATIONAL | ADDRESS_NUMBER_PLAN_ID_TELEPHONE); } else { return createAddressType(ADDRESS_TYPE_UNKNOWN | ADDRESS_NUMBER_PLAN_ID_TELEPHONE); } }
From source file:Main.java
public static long getTimeAsMillisecs(final Object iSize) { if (iSize == null) throw new IllegalArgumentException("Time is null"); if (iSize instanceof Number) // MILLISECS return ((Number) iSize).longValue(); String time = iSize.toString(); boolean number = true; for (int i = time.length() - 1; i >= 0; --i) { if (!Character.isDigit(time.charAt(i))) { number = false;/* w w w. ja v a 2 s .co m*/ break; } } if (number) // MILLISECS return Long.parseLong(time); else { time = time.toUpperCase(Locale.ENGLISH); int pos = time.indexOf("MS"); if (pos > -1) return Long.parseLong(time.substring(0, pos)); pos = time.indexOf("S"); if (pos > -1) return Long.parseLong(time.substring(0, pos)) * SECOND; pos = time.indexOf("M"); if (pos > -1) return Long.parseLong(time.substring(0, pos)) * MINUTE; pos = time.indexOf("H"); if (pos > -1) return Long.parseLong(time.substring(0, pos)) * HOUR; pos = time.indexOf("D"); if (pos > -1) return Long.parseLong(time.substring(0, pos)) * DAY; pos = time.indexOf('W'); if (pos > -1) return Long.parseLong(time.substring(0, pos)) * WEEK; pos = time.indexOf('Y'); if (pos > -1) return Long.parseLong(time.substring(0, pos)) * YEAR; // RE-THROW THE EXCEPTION throw new IllegalArgumentException("Time '" + time + "' has a unrecognizable format"); } }
From source file:Main.java
public static final int compareNatural(String firstString, String secondString) { int firstIndex = 0; int secondIndex = 0; Collator collator = Collator.getInstance(); while (true) { if (firstIndex == firstString.length() && secondIndex == secondString.length()) { return 0; }//from www . j av a 2 s. c o m if (firstIndex == firstString.length()) { return -1; } if (secondIndex == secondString.length()) { return 1; } if (Character.isDigit(firstString.charAt(firstIndex)) && Character.isDigit(secondString.charAt(secondIndex))) { int firstZeroCount = 0; while (firstString.charAt(firstIndex) == '0') { firstZeroCount++; firstIndex++; if (firstIndex == firstString.length()) { break; } } int secondZeroCount = 0; while (secondString.charAt(secondIndex) == '0') { secondZeroCount++; secondIndex++; if (secondIndex == secondString.length()) { break; } } if ((firstIndex == firstString.length() || !Character.isDigit(firstString.charAt(firstIndex))) && (secondIndex == secondString.length() || !Character.isDigit(secondString.charAt(secondIndex)))) { continue; } if ((firstIndex == firstString.length() || !Character.isDigit(firstString.charAt(firstIndex))) && !(secondIndex == secondString.length() || !Character.isDigit(secondString.charAt(secondIndex)))) { return -1; } if ((secondIndex == secondString.length() || !Character.isDigit(secondString.charAt(secondIndex)))) { return 1; } int diff = 0; do { if (diff == 0) { diff = firstString.charAt(firstIndex) - secondString.charAt(secondIndex); } firstIndex++; secondIndex++; if (firstIndex == firstString.length() && secondIndex == secondString.length()) { return diff != 0 ? diff : firstZeroCount - secondZeroCount; } if (firstIndex == firstString.length()) { if (diff == 0) { return -1; } return Character.isDigit(secondString.charAt(secondIndex)) ? -1 : diff; } if (secondIndex == secondString.length()) { if (diff == 0) { return 1; } return Character.isDigit(firstString.charAt(firstIndex)) ? 1 : diff; } if (!Character.isDigit(firstString.charAt(firstIndex)) && !Character.isDigit(secondString.charAt(secondIndex))) { if (diff != 0) { return diff; } break; } if (!Character.isDigit(firstString.charAt(firstIndex))) { return -1; } if (!Character.isDigit(secondString.charAt(secondIndex))) { return 1; } } while (true); } else { int aw = firstIndex; int bw = secondIndex; do { firstIndex++; } while (firstIndex < firstString.length() && !Character.isDigit(firstString.charAt(firstIndex))); do { secondIndex++; } while (secondIndex < secondString.length() && !Character.isDigit(secondString.charAt(secondIndex))); String as = firstString.substring(aw, firstIndex); String bs = secondString.substring(bw, secondIndex); int subwordResult = collator.compare(as, bs); if (subwordResult != 0) { return subwordResult; } } } }
From source file:gov.gtas.parsers.util.FlightUtils.java
/** * Separate flight carrier and flight number from single input string. * @param s/*from ww w . j a v a2 s.c om*/ * @return */ public static FlightNumber separateCarrierAndFlightNumber(String s) { StringBuffer fn = new StringBuffer(); int j; for (j = s.length() - 1; j >= 0; j--) { char c = s.charAt(j); if (Character.isDigit(c)) { fn.append(c); if (s.length() - fn.length() == MIN_CARRIER_LENG) { break; } else if (fn.length() == MAX_FLIGHT_NUM_LENG) { break; } } else { break; } } String carrier = s.substring(0, s.length() - fn.length()); return new FlightNumber(carrier, fn.reverse().toString()); }
From source file:Main.java
public static String getBaseName(String name, boolean bracketed) { String result = name;//w w w . j a v a 2 s . c o m if (bracketed) { if (result.charAt(result.length() - 1) != ')') return name; result = result.substring(0, result.length() - 1); } while (Character.isDigit(result.charAt(result.length() - 1))) result = result.substring(0, result.length() - 1); if (bracketed) { if (!result.substring(result.length() - 2).equals(" (")) //$NON-NLS-1$ return name; result = result.substring(0, result.length() - 2); } return result; }