* 提取字符串中爲字母的字符
*/
public static String returnResultMultiple(String str) {
String string = "";
if (str.equals("")) {
return "";
}
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (Character.isLetter(ch)) {
string = string + ch;
}
}
return string;
}
* 提取字符串中爲數字的字符
*/
public static String returnNumber(String str) {
String str2 = "";
if (str != null && !"".equals(str)) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
str2 += str.charAt(i);
}
}
return str2;
}
return str2;
}
* 將byte[]轉爲String
*
* @param b
* @return
*/
@SuppressLint("DefaultLocale")
public static String bytes2HexString(byte[] b) {
String ret = "";
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
ret += hex.toUpperCase();
}
return ret;
}
* 將String轉爲byte[]
*
* @param message
* @return
*/
private byte[] getHexBytes(String message) {
int len = message.length() / 2;
char[] chars = message.toCharArray();
String[] hexStr = new String[len];
byte[] bytes = new byte[len];
for (int i = 0, j = 0; j < len; i += 2, j++) {
hexStr[j] = "" + chars[i] + chars[i + 1];
bytes[j] = (byte) Integer.parseInt(hexStr[j], 16);
}
return bytes;
}