List of utility methods to do String to
String | convertStringToLiteral(String className, String value) convert String To Literal if (value == null) { return null; } else if ("String".equals(className)) { return "\"" + value.replaceAll("\'", "\\'") + "\""; } else if ("Number".equals(className)) { if (value.indexOf(".") == -1) { return "Integer.valueOf(" + value + ")"; } else { ... |
Object | convertStringToObject(String value, Class> type) Not support negative numeric value: - http://en.wikipedia.org/wiki/Double-precision_floating-point_format Object obj = null; try { if (String.class.equals(type)) { obj = value; if (Long.class.equals(type) || long.class.equals(type)) { obj = Long.parseLong(value); } else if (Integer.class.equals(type) || int.class.equals(type)) { ... |
byte[] | convertStringToPrimaryKey(String keyString) Converts a if ((keyString != null) && (!"".equals(keyString))) { keyString = keyString.toLowerCase(); byte[] bArray = new byte[(keyString.length() / 2)]; for (int i = 0; i < bArray.length; i++) { bArray[i] = (byte) Integer.parseInt(keyString.substring(i * 2, i * 2 + 2), 16); return bArray; return null; |
Object | convertStringToPrimitive(Object object, Class toType) convert String To Primitive if (toType == boolean.class || toType == Boolean.class) { return Boolean.valueOf((String) object); if (toType == char.class || toType == Character.class) { return new Character(((String) object).charAt(0)); if (toType == byte.class || toType == Byte.class) { return new Byte((String) object); ... |
Object | convertStringToPrimitive(String value, Class destinationClass) convert String To Primitive if ((destinationClass == int.class || destinationClass == Integer.class)) { return new Integer(value); if ((destinationClass == boolean.class || destinationClass == Boolean.class)) { return Boolean.valueOf(value); if ((destinationClass == short.class || destinationClass == Short.class)) { return new Short(value); ... |
String | convertStringToSafeFilename(String s) convert String To Safe Filename String ret = s.toLowerCase(); ret = ret.replaceAll("[\\\\\\/\\:\\*\\?\\\"\\<\\>\\|\\s\\,]", "-"); return ret; |
Object | convertStringToValue(String txt, Class> klass) convert String To Value Object v = null; try { if (klass.equals(Double.class) || klass.equals(Double.TYPE)) v = Double.parseDouble(txt); else if (klass.equals(Float.class) || klass.equals(Float.TYPE)) v = Float.parseFloat(txt); else if (klass.equals(Integer.class) || klass.equals(Integer.TYPE)) v = Integer.parseInt(txt); ... |
String | convertStringToVarName(final String str) convert String To Var Name return str.toUpperCase().replaceAll("[:punct:\\(\\)\\]\\['-]", "").replaceAll(" +", "_"); |
byte[] | convertStringToWord(String strValue) Converts a given string into a word of bytes byte[] word = new byte[2]; try { byte intRegVal = 0; for (int i = strValue.length(); i > 0; i--) { intRegVal = (byte) (intRegVal + Math.pow(16, strValue.length() - i) * Byte.parseByte(strValue.substring(i - 1, i), 16)); word[0] = (byte) (intRegVal >>> 8 & 0xFF); ... |
String | convertStringWithReplacementPattern(final String originalString, final String pattern, final String replace) This method returns a string with characters replaced. if (originalString != null) { final int len = pattern.length(); final StringBuffer sb = new StringBuffer(); int found = -1; int start = 0; while ((found = originalString.indexOf(pattern, start)) != -1) { sb.append(originalString.substring(start, found)); sb.append(replace); ... |