List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
public static final String getKorean(String str) { String korean = ""; char syllable; for (int i = 0; i < str.length(); i++) { syllable = str.charAt(i); if (Character.getType(syllable) == 5) korean += syllable;/* ww w.ja va 2s. c o m*/ else return korean; } return korean; }
From source file:Main.java
public static String GetStringBackFromScrapedString(String input) { String scrampedString = ""; for (int icount = 0; icount < input.length(); icount++) { char c = (char) (input.charAt(icount) - 12); scrampedString = scrampedString + c; }// w w w.ja v a 2 s . c om return scrampedString; }
From source file:Main.java
protected static boolean needCData(String value) { final int length = value.length(); for (int i = 0; i < length; i++) { final char c = value.charAt(i); if (c <= HIGHEST_ENCODABLE_TEXT_CHAR) { if (c <= 0x001f) { if (c != '\n' && c != '\t' && c != '\r') { // fine as is return true; }//from w ww . ja va 2 s .c o m } else if (c == '<' || c == '&') { return true; } } } return false; }
From source file:Main.java
private static boolean isPersianNumberLegal(String number) { for (int i = 0; i < number.length(); i++) if (!PERSIAN_TO_ENGLISH.containsKey(number.charAt(i))) return false; return true;/*from ww w .ja v a2 s . com*/ }
From source file:Main.java
/** * Get a parameter name from a method name. * * @param methodName the method name/*from w ww . j a v a2 s . co m*/ * @return the parameter name */ public static String parameterName(final String methodName) { StringBuilder buf = new StringBuilder(methodName.substring(3)); buf.setCharAt(0, Character.toLowerCase(methodName.charAt(3))); return buf.toString(); }
From source file:Main.java
/** * Converts the seperators of the coords to the WKT from ts and cs * * @param coords the coords string to convert * @param ts the separator that separates 2 coordinates * @param cs the separator between 2 numbers in a coordinate *//*from ww w . ja va2 s . co m*/ public static String toWktCoords(Object coords, Object ts, Object cs) { String coordsString = coords.toString(); char tsString; if (ts == null || ts.toString().length() == 0) { tsString = TS_DEFAULT; } else { tsString = ts.toString().charAt(0); } char csString; if (cs == null || cs.toString().length() == 0) { csString = CS_DEFAULT; } else { csString = cs.toString().charAt(0); } if (tsString == TS_WKT && csString == CS_WKT) { return coordsString; } if (tsString == CS_WKT) { tsString = ';'; coordsString = coordsString.replace(CS_WKT, tsString); } coordsString = coordsString.replace(csString, CS_WKT); String result = coordsString.replace(tsString, TS_WKT); char lastChar = result.charAt(result.length() - 1); if (result.charAt(result.length() - 1) == TS_WKT || lastChar == CS_WKT) { result = result.substring(0, result.length() - 1); } return result; }
From source file:Main.java
/** * Return PITarget from Processing Instruction (PI) as defined in * XML 1.0 Section 2.6 Processing Instructions * <code>[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'</code> */// w w w. j a v a 2 s . co m public static String getPITarget(XmlPullParser pp) throws IllegalStateException { int eventType; try { eventType = pp.getEventType(); } catch (XmlPullParserException ex) { // should never happen ... throw new IllegalStateException( "could not determine parser state: " + ex + pp.getPositionDescription()); } if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) { throw new IllegalStateException("parser must be on processing instruction and not " + XmlPullParser.TYPES[eventType] + pp.getPositionDescription()); } final String PI = pp.getText(); for (int i = 0; i < PI.length(); i++) { if (isS(PI.charAt(i))) { // assert i > 0 return PI.substring(0, i); } } return PI; }
From source file:Main.java
private static void escapeElementEntities(StringBuilder sb, String text) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; default:// w w w . j a va2 s . co m sb.append(c); } } }
From source file:Main.java
/** * Compare two strings, and return the index at which the strings begin to differ. * <p>//from ww w.ja v a 2s.c o m * E.g. strdiff("i am a machine", "i am a robot") -> 7 * </p> * * @return the index where s2 and s1 begin to differ; -1 if they are equal */ public static int differenceAt(String s1, String s2) { int i; for (i = 0; (i < s1.length()) && (i < s2.length()); ++i) { if (s1.charAt(i) != s2.charAt(i)) { break; } } if ((i < s2.length()) || (i < s1.length())) { return i; } return -1; }
From source file:Main.java
public static String xmlEncode(String str) { String ret = ""; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c >= 128 || c < 32 || c == '\'' || c == '"' || c == '<' || c == '>') { if (c > 0xFF) ret += "&#x" + String.format("%04x", (int) c) + ";"; else//www . ja va 2 s . c o m ret += "&#x" + String.format("%02x", (int) c) + ";"; } else ret += c; } return ret; }