1、Java反转字符,常用于卡号反转;eg: 5C30A50D --> 0DA5305C
5C 30 A5 0D
0D A5 30 5C
/**
* 反转字符--常用于卡号反转;eg: 5C30A50D --> 0DA5305C
*
* @param number
* @return
*/
public static String reverseNumber(String number) {
String newStr = "";
if (!StringUtils.isBlank(number)) {
int length = number.length();
if (length > 1 && length % 2 == 0) {
for (int i = 0; i < length; i++) {
if (i % 2 == 0) {
newStr += number.charAt(length - i - 2);
} else {
newStr += number.charAt(length - i);
}
}
}
}
return newStr;
}
2、Java字符串处理,仅用于html页面显示
/**
* 竖
* 直
* 显
* 示
* 字
* 符
* 串
*
* @note 仅用于html页面显示
* @param string
* @return
*/
public static String showVertical(String string){
StringBuffer sb = new StringBuffer();
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
sb.append(c);
sb.append("<br>");
}
return sb.toString();
}
/**
* 竖直
* 显示
* 字符
* 串
*
* @note 仅用于html页面显示
* @param string
* @return
*/
public static String showVertical(String string, int colNum) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
sb.append(c);
if (i != 0 && colNum != 0 && (i + 1) % colNum == 0) {
sb.append("<br>");
}
}
return sb.toString();
}