66package com .anhtester .utils ;
77
88import java .nio .charset .StandardCharsets ;
9+ import java .text .Normalizer ;
910import java .util .Arrays ;
1011
1112public class LanguageUtils {
@@ -46,14 +47,22 @@ public static char removeAccent(char ch) {
4647 return ch ;
4748 }
4849
49- public static String removeAccent (String str ) {
50- StringBuilder sb = new StringBuilder (str );
50+ public static String removeAccent (String text ) {
51+ StringBuilder sb = new StringBuilder (text );
5152 for (int i = 0 ; i < sb .length (); i ++) {
5253 sb .setCharAt (i , removeAccent (sb .charAt (i )));
5354 }
5455 return sb .toString ();
5556 }
5657
58+ // public static String removeAccent(String text) {
59+ // // Chuẩn hóa chuỗi thành dạng Unicode tổ hợp (NFD)
60+ // String normalized = Normalizer.normalize(text, Normalizer.Form.NFD);
61+ // // Loại bỏ các ký tự dấu (dấu thanh, dấu móc, ...)
62+ // String accentRemoved = normalized.replaceAll("\\p{M}", "");
63+ // return accentRemoved;
64+ // }
65+
5766 public static String convertCharset_ISO_8859_1_To_UTF8 (String text ) {
5867 return new String (text .getBytes (StandardCharsets .ISO_8859_1 ), StandardCharsets .UTF_8 );
5968 }
@@ -65,4 +74,10 @@ public static String convertCharset_UTF8_To_ISO_8859_1(String text) {
6574 public static String convertCharset_US_ASCII_To_UTF8 (String text ) {
6675 return new String (text .getBytes (StandardCharsets .US_ASCII ), StandardCharsets .UTF_8 );
6776 }
77+
78+ // public static void main(String[] args) {
79+ // String input = "Tiếng Việt có dấu";
80+ // String output = removeAccent(input);
81+ // System.out.println(output);
82+ // }
6883}
0 commit comments