List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
public static boolean canBeCompilerOptionValue(final String text) { if (text.startsWith("-")) { // option or negative number return text.length() > 1 && Character.isDigit(text.charAt(1)); }/*w w w .j ava 2 s . c o m*/ return !text.startsWith("+"); }
From source file:Main.java
/** * Convert a packed LCCN String to MARC display format. * @param packedLCCN an LCCN String in packed storage format (e.g. 'n 2001050268'). * @return an LCCN String in MARC display format (e.g. 'n2001-50268'). *///from www . ja v a 2s . c om public static String toLCCNDisplay(String packedLCCN) { StringBuffer sb = new StringBuffer(); if (Character.isDigit(packedLCCN.charAt(2))) { sb.append(packedLCCN.substring(0, 2).trim()); sb.append(packedLCCN.substring(2, 6)); sb.append("-"); int i = Integer.parseInt(packedLCCN.substring(6).trim()); sb.append(Integer.toString(i)); } else { sb.append(packedLCCN.substring(0, 3).trim()); sb.append(packedLCCN.substring(3, 5)); sb.append("-"); int i = Integer.parseInt(packedLCCN.substring(5).trim()); sb.append(Integer.toString(i)); } return sb.toString(); }
From source file:Main.java
public static String getSetterName(String fieldName) { if (fieldName == null || fieldName.length() == 0) return ""; String first = String.valueOf(fieldName.charAt(0)); first = first.toUpperCase();/*from www.j a va 2s . co m*/ return "set" + first + fieldName.substring(1); }
From source file:Main.java
/** * Ensures that the given pathname ends with the path separator character * of this operating system./*from w ww. j a v a 2s . c o m*/ * * @param pathName * @return */ public final static String ensureEndsWithPathSeparatorChar(String pathName) { if (pathName.length() == 0) return File.pathSeparator; else if (pathName.charAt(pathName.length() - 1) == File.pathSeparatorChar) return pathName; else return pathName + File.pathSeparatorChar; }
From source file:com.cuebiq.presto.scalar.HashingFunctions.java
@Description("shuffles using a pseudo random algorithm.") @ScalarFunction//from ww w . j a va 2 s. c o m @SqlType(StandardTypes.VARCHAR) public static Slice shuffle_string(@SqlType(StandardTypes.VARCHAR) Slice string) { String id = string.toStringUtf8(); Random rnd = new Random(id.charAt(0)); byte[] bytes = id.getBytes(); for (int i = bytes.length; i > 1; i--) { swap(bytes, i - 1, rnd.nextInt(i)); } return Slices.wrappedBuffer(bytes); }
From source file:Main.java
public static String string2Unicode(String string) { StringBuffer unicode = new StringBuffer(); for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); unicode.append("\\" + "u" + Integer.toHexString(c)); }//w w w. j a v a 2 s . c o m return unicode.toString(); }
From source file:Main.java
public static boolean isToday(String binary, int actualDay) { boolean today; int realDay = (actualDay > 1) ? actualDay - 2 : 6; today = binary.charAt(realDay) == '1'; return today; }
From source file:StringUtils.java
/** * Returns true, if the argument contains a number, otherwise false. * In a quick test this is roughly the same speed as Integer.parseInt() * if the argument is a number, and roughly ten times the speed, if * the argument is NOT a number.//from ww w.j a v a 2s .c o m * * @since 2.4 * @param s String to check * @return True, if s represents a number. False otherwise. */ public static boolean isNumber(String s) { if (s == null) return false; if (s.length() > 1 && s.charAt(0) == '-') s = s.substring(1); for (int i = 0; i < s.length(); i++) { if (!Character.isDigit(s.charAt(i))) return false; } return true; }
From source file:Main.java
private static char labelFor(String username) { return Character.toUpperCase(username.charAt(0)); }
From source file:Main.java
public static byte[] stringToHexByteArray(String string) { byte[] bytes = new byte[4]; if (string != null && string.length() >= 4) { bytes[0] = (byte) (string.charAt(0) == '1' ? 0x01 : 0x00); bytes[1] = (byte) (string.charAt(1) == '1' ? 0x01 : 0x00); bytes[2] = (byte) (string.charAt(2) == '1' ? 0x01 : 0x00); bytes[3] = (byte) (string.charAt(3) == '1' ? 0x01 : 0x00); }//ww w . j av a 2 s. c o m return bytes; }