List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
static int getNumDashes(final String category) { int i = 0;//from w ww . j a v a2 s . c o m while (i < category.length() && (int) category.charAt(i) == (int) '-') { i++; } return i; }
From source file:Main.java
public static char RandomCharFromStr(String str) { Random random = new Random(); int index = random.nextInt(str.length()); return str.charAt(index); }
From source file:Main.java
private static void validateLocalePart(String localePart) { for (int i = 0; i < localePart.length(); i++) { char ch = localePart.charAt(i); if (ch != '_' && ch != ' ' && !Character.isLetterOrDigit(ch)) { throw new IllegalArgumentException( "Locale part \"" + localePart + "\" contains invalid characters"); }/*w w w .ja v a2s .co m*/ } }
From source file:Main.java
public static boolean isEmptyText(Text txt) { String s = txt.getData(); for (int i = 0; i < s.length(); ++i) { if (!Character.isWhitespace(s.charAt(i))) return false; }// w ww. ja v a 2s . c o m return true; }
From source file:Main.java
public static void writeString(final DataOutputStream output, final String value) throws IOException { for (int i = 0; i < value.length(); i++) { output.write(value.charAt(i)); }//from ww w . j a va 2 s. com }
From source file:Main.java
private static String capitalize(String s) { if (s == null || s.length() == 0) { return ""; }//from ww w . j a v a 2 s .c o m char first = s.charAt(0); if (Character.isUpperCase(first)) { return s; } else { return Character.toUpperCase(first) + s.substring(1); } }
From source file:Main.java
public static String capitalize(String s) { if (s == null || s.length() == 0) { return ""; }// ww w. j a va2 s.c o m char first = s.charAt(0); if (Character.isUpperCase(first)) { return s; } else { return Character.toUpperCase(first) + s.substring(1); } }
From source file:Main.java
/** * Returns the {@code String} instance with detecting the Japanese encoding. * @throws UnsupportedEncodingException if it fails to detect the encoding. *//*ww w . j av a 2s . co m*/ static String toStringWithEncodingDetection(ByteBuffer buffer) throws UnsupportedEncodingException { for (String encoding : JAPANESE_ENCODING_LIST) { buffer.position(0); try { Charset charset = Charset.forName(encoding); CharBuffer result = charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT) .onUnmappableCharacter(CodingErrorAction.REPORT).decode(buffer); String str = result.toString(); if (str.length() > 0 && str.charAt(0) == 0xFEFF) { // Remove leading BOM if necessary. str = str.substring(1); } return str; } catch (Exception e) { // Ignore exceptions, and retry next encoding. } } throw new UnsupportedEncodingException("Failed to detect encoding"); }
From source file:Main.java
public static boolean isAlphaString(String s) { boolean b = true; for (int i = 0; i < s.length(); i++) { if (!isAlpha(s.charAt(i))) { b = false;//from ww w.j a v a 2s . c om break; } } return b; }
From source file:Main.java
public static String capitial(String str) { if (str == "" || str.length() == 0) return ""; char first = str.charAt(0); if (Character.isUpperCase(first)) return str; else/*from w w w . ja v a 2 s . c o m*/ return Character.toUpperCase(first) + str.substring(1); }