用户输入缅甸数字(使用特殊的软键盘)。 然后,我需要增加该数字。但是当我解析输入时,digitOne变为阿拉伯语。有什么办法可以保留缅甸吗?
String digitText= editText.getText().toString();
Integer digitOne = Integer.parseInt(digitText);
答案 0 :(得分:0)
我能找到的唯一解决方案是在算术运算后简单地将其音译:
public static String getMyanmarDigitsText(@NonNull String numericStr) {
for (int j = 0; j < numericStr.length(); j++) {
String character = numericStr.substring(j, j + 1);
String replacement = MyUtils.getMyanmarDigitSymbol(character);
if (replacement != null) numericStr = numericStr.replace(character, replacement);
}
return numericStr;
}
public static String getEnglishDigitsText(@NonNull String numericStr) {
for (int j = 0; j < numericStr.length(); j++) {
String character = numericStr.substring(j, j + 1);
String replacement = MyUtils.getEnglishDigitSymbol(character);
if (replacement != null) numericStr = numericStr.replace(character, replacement);
}
return numericStr;
}
@Nullable
private static String getMyanmarDigitSymbol(String digit) {
switch (digit) {
case "0":
return "၀";
case "1":
return "၁";
case "2":
return "၂";
case "3":
return "၃";
case "4":
return "၄";
case "5":
return "၅";
case "6":
return "၆";
case "7":
return "၇";
case "8":
return "၈";
case "9":
return "၉";
default:
return null;
}
}
@Nullable
public static String getEnglishDigitSymbol(String digit) {
switch (digit) {
case "၀":
return "0";
case "၁":
return "1";
case "၂":
return "2";
case "၃":
return "3";
case "၄":
return "4";
case "၅":
return "5";
case "၆":
return "6";
case "၇":
return "7";
case "၈":
return "8";
case "၉":
return "9";
default:
return null;
}
}
public static boolean isMyanmarDigits(String numericStr) {
return numericStr.contains("၀")
|| numericStr.contains("၁")
|| numericStr.contains("၂")
|| numericStr.contains("၃")
|| numericStr.contains("၄")
|| numericStr.contains("၅")
|| numericStr.contains("၆")
|| numericStr.contains("၇")
|| numericStr.contains("၈")
|| numericStr.contains("၉");
}
public static boolean isEnglishDigits(String numericStr) {
return numericStr.contains("0")
|| numericStr.contains("1")
|| numericStr.contains("2")
|| numericStr.contains("3")
|| numericStr.contains("4")
|| numericStr.contains("5")
|| numericStr.contains("6")
|| numericStr.contains("7")
|| numericStr.contains("8")
|| numericStr.contains("9");
}f