The list of methods to do String to are organized into topic(s).
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':
...
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());
T
convertString(String value, Class type) 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;
...