2024. 4. 15. 19:47 카테고리 없음
금융 데이터 영문 전각 -> 반각 처리
public class FullwidthToHalfwidthConverter {
public static String convertFullwidthToHalfwidth(String input) {
if (input == null || input.isEmpty()) {
return input;
}
StringBuilder sb = new StringBuilder();
for (char c : input.toCharArray()) {
// 유니코드 범위에 따라 전각 문자를 반각 문자로 변환
if (c >= '\uFF01' && c <= '\uFF5E') {
sb.append((char) (c - '\uFF01' + '!'));
} else if (c == '\u3000') { // 공백 문자
sb.append(' ');
} else {
sb.append(c);
}
}
return sb.toString();
}
public static void main(String[] args) {
String fullwidth = "ABCDEFG"; // 전각 알파벳
String converted = convertFullwidthToHalfwidth(fullwidth);
System.out.println("Converted: " + converted);
}
}