List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
/** * Get the mac address for mesh usage(For mesh require the BSSID uppercase and without colon). It is an inverse * method for getRawMacAddress// ww w . j av a2 s . co m * * @param bssid the bssid get from wifi scan * @return the mac address for mesh usage */ public static String getMacAddressForMesh(String bssid) { StringBuilder sb = new StringBuilder(); char c; for (int i = 0; i < bssid.length(); i++) { c = bssid.charAt(i); if (c != ':') { sb.append(c); } } return sb.toString().toUpperCase(Locale.US); }
From source file:Main.java
public static String generateRandomString(int len) { String all = "0123456789abcdefghijklmnopqrstuvwxyz"; StringBuffer s = new StringBuffer(); for (int i = 0; i < len; i++) { s.append(all.charAt(getRandomNum(36))); }// w w w . j a v a2 s. c om return s.toString(); }
From source file:Main.java
private static String __getNextWord(String s, int pos) { int i = 0;/*from ww w . j a v a 2 s . c om*/ StringBuilder sb = new StringBuilder(); while (pos + i < s.length()) { char c = s.charAt(pos + i); if (Character.isLetter(c)) { sb.append(c); } else { break; } i++; } if (sb.length() == 0) return null; return sb.toString(); }
From source file:Main.java
public static String upperFirstAndAddPre(String str, String preString) { if (str == null || preString == null) { return null; }/*w ww . j av a 2s.c om*/ return preString + Character.toUpperCase(str.charAt(0)) + str.substring(1); }
From source file:Main.java
public static void putInHashMapByGivenAttribute(HashMap map, Object obj, String attribName) { try {//w w w . ja v a 2s . com Class class1 = obj.getClass(); String methodName = "get" + Character.toUpperCase(attribName.charAt(0)) + attribName.substring(1); Method method = class1.getMethod(methodName, new Class[0]); Object attributeValue = method.invoke(obj, new Object[0]); map.put(attributeValue, obj); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean isInteger(String s, int radix) { if (s.isEmpty()) return false; for (int i = 0; i < s.length(); i++) { if (i == 0 && s.charAt(i) == '-') { if (s.length() == 1) return false; else//from ww w. j a v a2 s . c om continue; } if (Character.digit(s.charAt(i), radix) < 0) return false; } return true; }
From source file:Main.java
public static boolean contains(final String searchableString, final String restriction) { int i = 0, j = 0; while ((i < restriction.length()) && (j < searchableString.length())) { if (restriction.charAt(i) == searchableString.charAt(j)) { ++i;//ww w .j a v a 2 s .com ++j; } else { ++j; } } if (i == restriction.length()) { return true; } return false; }
From source file:Main.java
public static URL createURL(String fileName) throws MalformedURLException { URL url = null;//from www.j av a 2 s .co m try { url = new URL(fileName); } catch (MalformedURLException ex) { File f = new File(fileName); try { String path = f.getAbsolutePath(); String fs = System.getProperty("file.separator"); if (fs.length() == 1) { char sep = fs.charAt(0); if (sep != '/') { path = path.replace(sep, '/'); } if (path.charAt(0) != '/') { path = '/' + path; } } path = "file://" + path; url = new URL(path); } catch (MalformedURLException e) { throw e; } } return url; }
From source file:Main.java
public static boolean containsChinese(String s) { if (null == s || "".equals(s.trim())) return false; for (int i = 0; i < s.length(); i++) { if (isChinese(s.charAt(i))) return true; }/*from ww w .ja v a 2 s . c o m*/ return false; }
From source file:exm.stc.tclbackend.tree.Proc.java
/** * Check that there are no invalid characters */// w w w . java 2 s . c o m private static void checkTclFunctionName(String name) { for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (Character.isLetter(c) || Character.isDigit(c) || c == ':' || c == '_' || c == '=' || c == '-' || c == '<' || c == '>') { // Whitelist of characters } else { throw new STCRuntimeError("Bad character '" + c + "' in tcl function name " + name); } } }