我有字符串 a= "L1-23Миграција од VPN и промена на брзина ACTELIS Agregator alternativna 8-/208" ;
我希望我的每个字符串都检查字符串中是否有一些西里尔字母并将它们转换为英文:
输出应如下所示:
L1-23Migracija od VPN i promena na brzina ACTELIS Agregator alternativna 8-/208
谢谢!
我在 stackoverflow Transliteration from Cyrillic to Latin ICU4j java上找到了这种方法,它用于将西里尔文(俄语)转换为拉丁文(但如果需要,您可以将其转换为其他方式)。我对其进行了一些调整,使其与马其顿西里尔字母兼容(我相信这就是您所需要的)。这里是:
public static String convertCyrilic(String message){
char[] abcCyr = {' ','а','б','в','г','д','ѓ','е', 'ж','з','ѕ','и','ј','к','л','љ','м','н','њ','о','п','р','с','т', 'ќ','у', 'ф','х','ц','ч','џ','ш', 'А','Б','В','Г','Д','Ѓ','Е', 'Ж','З','Ѕ','И','Ј','К','Л','Љ','М','Н','Њ','О','П','Р','С','Т', 'Ќ', 'У','Ф', 'Х','Ц','Ч','Џ','Ш','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','/','-'};
String[] abcLat = {" ","a","b","v","g","d","]","e","zh","z","y","i","j","k","l","q","m","n","w","o","p","r","s","t","'","u","f","h", "c",";", "x","{","A","B","V","G","D","}","E","Zh","Z","Y","I","J","K","L","Q","M","N","W","O","P","R","S","T","KJ","U","F","H", "C",":", "X","{", "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","/","-"};
StringBuilder builder = new StringBuilder();
for (int i = 0; i < message.length(); i++) {
for (int x = 0; x < abcCyr.length; x++ ) {
if (message.charAt(i) == abcCyr[x]) {
builder.append(abcLat[x]);
}
}
}
return builder.toString();
}
然后就用
String converted = convertCyrillic(a);