Converting Numbers to Local (UTF8) Bengali numbers in JasperReports & MySQL

前端 未结 2 379
野性不改
野性不改 2021-01-13 22:18

I am trying to convert the English numbers to Bengali numbers before filling the report. The data i am getting from MySQL:

SELECT brand.id,brand.brand,model.         


        
相关标签:
2条回答
  • 2021-01-13 22:51

    You also could create a replacement String in the Java code and use it in the parameters map:

       String replacedOne = one.getText().replaceAll("0","০").replaceAll("1","১").replaceAll("2","২").replaceAll("3","৩").replaceAll("4","৪").replaceAll("5","৫").replaceAll("6","৬").replaceAll("7","৭").replaceAll("8","৮").replaceAll("9","৯");
       parameters.put("replacedID",replacedOne);
    

    Or better, you can perform the replacement directly in your jrxml file, with no need to modify the java file, by using this (very long) expression instead of $F{model}:

    $F{model}.replaceAll("0","০").replaceAll("1","১").replaceAll("2","২").replaceAll("3","৩").replaceAll("4","৪").replaceAll("5","৫").replaceAll("6","৬").replaceAll("7","৭").replaceAll("8","৮").replaceAll("9","৯");
    
    0 讨论(0)
  • 2021-01-13 22:52

    For new Learner

    private String getStringInBangla(String string) {
        Character[] bangla_number = {'০', '১', '২', '৩', '৪', '৫', '৬', '৭', '৮', '৯'};
        Character[] eng_number = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        StringBuilder values = new StringBuilder();
        char[] character = string.toCharArray();
        for (char value : character) {
            char c = ' ';
            for (int j = 0; j < eng_number.length; j++) {
                if (value == eng_number[j]) {
                    c = bangla_number[j];
                    break;
                } else {
                    c = value;
                }
            }
            values.append(c);
        }
        return values.toString();
    }
    
    0 讨论(0)
提交回复
热议问题