List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:FileUtils.java
public static URL getRelativePathToURL(String root, String name) { String dir = root != null ? root : ""; try {/* ww w .j ava 2s . com*/ String file = getFilePath(name); if (file.length() > 0 && file.charAt(0) != '/') { dir = dir != null ? dir.replace(SEPARATOR, '/') + '/' : "/"; if (dir.charAt(0) != '/') dir = "/" + dir; file = dir + file; } return new URL("file", "", file); } catch (MalformedURLException e) { return null; } }
From source file:Main.java
public static String invert(String s) { String temp = ""; for (int i = s.length() - 1; i >= 0; i--) temp += s.charAt(i); return temp;/* w w w .j av a 2s .co m*/ }
From source file:com.gargoylesoftware.js.CodeUpdater.java
private static boolean isCodeStart(final String line) { return !line.isEmpty() && Character.isAlphabetic(line.charAt(0)) && !line.startsWith("package") && !line.startsWith("import"); }
From source file:Main.java
public static String shortenText(final String content, final int length) { String result = content.substring(0, length); if (content.charAt(length) != ' ') result = result.substring(0, result.lastIndexOf(" ")); return result; }
From source file:eu.scape_project.hawarp.utils.StringUtils.java
public static String ensureTrailSep(String path) { if (path.charAt(path.length() - 1) != File.separatorChar) { path += File.separator;/*w ww . j a v a 2s . co m*/ } return path; }
From source file:Main.java
public static String getNifLetter(int dni) { String nifChars = "TRWAGMYFPDXBNJZSQVHLCKET"; int module = dni % 23; Character nifChar = nifChars.charAt(module); return nifChar.toString(); }
From source file:Main.java
public static boolean isAzStyle(String peer_id) { if (peer_id.charAt(0) != '-') { return false; }/*from w w w .j a v a 2 s . c o m*/ if (peer_id.charAt(7) == '-') { return true; } /** * Hack for FlashGet - it doesn't use the trailing dash. * Also, LH-ABC has strayed into "forgetting about the delimiter" territory. * * In fact, the code to generate a peer ID for LH-ABC is based on BitTornado's, * yet tries to give an Az style peer ID... oh dear. * * BT Next Evolution seems to be in the same boat as well. * * KTorrent 3 appears to use a dash rather than a final character. */ if (peer_id.substring(1, 3).equals("FG")) { return true; } if (peer_id.substring(1, 3).equals("LH")) { return true; } if (peer_id.substring(1, 3).equals("NE")) { return true; } if (peer_id.substring(1, 3).equals("KT")) { return true; } if (peer_id.substring(1, 3).equals("SP")) { return true; } return false; }
From source file:StringUtil.java
/** * Removes the double quote from the start and end of the supplied string if * it starts and ends with this character. This method does not create a new * string if <tt>text</tt> doesn't start and end with double quotes, the * <tt>text</tt> object itself is returned in that case. * /*from w w w.jav a 2 s. c o m*/ * @param text * The string to remove the double quotes from. * @return The trimmed string, or a reference to <tt>text</tt> if it did * not start and end with double quotes. */ public static String trimDoubleQuotes(String text) { int textLength = text.length(); if (textLength >= 2 && text.charAt(0) == '"' && text.charAt(textLength - 1) == '"') { return text.substring(1, textLength - 1); } return text; }
From source file:TextUtilities.java
/** * Locates the start of the word at the specified position. * // www . j av a2 s. co m * @param line * The text * @param pos * The position */ public static int findWordStart(String line, int pos, String noWordSep) { char ch = line.charAt(pos - 1); if (noWordSep == null) noWordSep = ""; boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1); int wordStart = 0; for (int i = pos - 1; i >= 0; i--) { ch = line.charAt(i); if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) { wordStart = i + 1; break; } } return wordStart; }
From source file:Main.java
private static char getType(Object object) { String s = object.getClass().getName(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '[') { continue; }/*from w w w . j av a 2 s .c o m*/ return s.charAt(i); } return 0; }