List of utility methods to do String to
int | convertString(char firstCharacter, String value) convert String int result = 0; for (int i = 0; i < value.length(); i++) { result = result * LETTER_BASE + value.charAt(i) - firstCharacter; return result; |
String | convertString(Object obj, String nullTo) convert String return obj == null ? nullTo : obj.toString();
|
String | convertString(String label) Escape all occurences of newline chars '\n', quotes \", etc. char[] ch = label.toCharArray(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < ch.length; i++) { switch (ch[i]) { case '\n': buf.append("\\n"); break; case '\r': ... |
String | convertString(String s) convert String if (s == null) { return ""; return s; |
Object | convertString(String s, Class> cls) Convert a string into an object of given type. if (cls == Integer.class) { return Integer.valueOf(s); } else if (cls == String.class) { return s; } else { throw new IllegalArgumentException("Don't know how to convert string to " + cls.getName()); |
String | convertString(String strValue) convert String return (strValue == null || strValue.equals("")) ? "" : strValue; |
T | convertString(String value, Class convert String if (type.equals(Long.class)) return (T) Long.valueOf(value); if (type.equals(Double.class)) return (T) Double.valueOf(value); if (type.equals(Integer.class)) return (T) Integer.valueOf(value); if (type.equals(Boolean.class)) return (T) Boolean.valueOf(value); ... |
byte[] | convertString2Bytes(String str) convert String Bytes byte[] result = new byte[str.length()]; for (int i = 0; i < str.length(); i++) { result[i] = (byte) str.charAt(i); return result; |
String | convertString2GSonString(String str) convert String G Son String str = str.replace("\"", "\\\"").replace("\n", "\\\n"); StringBuffer ostr = new StringBuffer(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if ((ch >= 0x0020) && (ch <= 0x007e)) { ostr.append(ch); } else { ostr.append("\\u"); ... |
float[] | convertStringArrayToFloatArray(String[] num) Convert array of strings to array of float if (num != null) { float fArray[] = new float[num.length]; for (int i = 0; i < num.length; i++) { fArray[i] = Float.parseFloat(num[i]); return fArray; return null; ... |