如何在 xhtml 中显示从 java 方法检索到的阿拉伯数字
How to show Arabic numbers retrieved from java method in xhtml
我需要你的帮助才能在 xhtml 页面中显示阿拉伯数字。目前,我在 xhtml 页面中得到的数字为 (???? 问号),因为当我在 Jdeveloper 中保存以下方法时,阿拉伯数字将被转换为问号。此方法会将英文数字的字符串转换为阿拉伯数字,其代码如下:
String str ="";
StringBuilder builder = new StringBuilder();
str = "1234566.555";
char[] arabicChars = {'٠','١','٢','٣','٤','٥','٦','٧','٨','٩'};
for(int i =0;i<str.length();i++)
{
if(Character.isDigit(str.charAt(i)))
{
builder.append(arabicChars[(int)(str.charAt(i))-48]);
}
else
{
builder.append(str.charAt(i));
}
}
而 xhtml 代码是:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h:outputText value="#{user1.builder}"/>
</h:body>
</html>
</f:view>
此函数有助于将英文数字转换为阿拉伯数字:
StringBuilder builder = new StringBuilder();
private String arabicDigits="";
public String arabicNumners(String englishNumber) {
String str=englishNumber;
char[] arabicChars = {'\u0660','\u0661','\u0662','\u0663','\u0664','\u0665','\u0666','\u0667','\u0668','\u0669'};
for(int i =0;i<str.length();i++)
{
if(Character.isDigit(str.charAt(i)))
{
builder.append(arabicChars[(int)(str.charAt(i))-48]);
}
else
{
builder.append(str.charAt(i));
}
}
System.out.println("Number in English : "+str);
System.out.println("Number In Arabic : "+builder.toString() );
return builder.toString();
}
我需要你的帮助才能在 xhtml 页面中显示阿拉伯数字。目前,我在 xhtml 页面中得到的数字为 (???? 问号),因为当我在 Jdeveloper 中保存以下方法时,阿拉伯数字将被转换为问号。此方法会将英文数字的字符串转换为阿拉伯数字,其代码如下:
String str ="";
StringBuilder builder = new StringBuilder();
str = "1234566.555";
char[] arabicChars = {'٠','١','٢','٣','٤','٥','٦','٧','٨','٩'};
for(int i =0;i<str.length();i++)
{
if(Character.isDigit(str.charAt(i)))
{
builder.append(arabicChars[(int)(str.charAt(i))-48]);
}
else
{
builder.append(str.charAt(i));
}
}
而 xhtml 代码是:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h:outputText value="#{user1.builder}"/>
</h:body>
</html>
</f:view>
此函数有助于将英文数字转换为阿拉伯数字:
StringBuilder builder = new StringBuilder();
private String arabicDigits="";
public String arabicNumners(String englishNumber) {
String str=englishNumber;
char[] arabicChars = {'\u0660','\u0661','\u0662','\u0663','\u0664','\u0665','\u0666','\u0667','\u0668','\u0669'};
for(int i =0;i<str.length();i++)
{
if(Character.isDigit(str.charAt(i)))
{
builder.append(arabicChars[(int)(str.charAt(i))-48]);
}
else
{
builder.append(str.charAt(i));
}
}
System.out.println("Number in English : "+str);
System.out.println("Number In Arabic : "+builder.toString() );
return builder.toString();
}