【发布时间】:2013-01-18 23:55:59
【问题描述】:
我正在通过 android 中的 USB 通信以扩展 ASCII 字符的形式接收字符串文本,例如
String receivedText = "5286T11ɬ ªË ¦¿¯¾ ¯¾ ɬ ¨¬°:A011605286 ª¿ª ¾®:12:45 ¸Í®°:(9619441121)ª¿ª:-, ®¹¿¦Í°¾ ¡ ®¹¿¦Í°¾ ª¨À, ¾¦¿µ²À ¸Í, ¾¦¿µ²À ªÂ°Íµ °¿®¾°Í͸:- ¡Í°Éª:-, ¬¾¹°, ¸¾¤¾Í°Â¼ ªÂ°Íµ~";
现在这些字符在印地语中表示一个字符串。
我不知道如何将此接收到的字符串转换为印地语等效文本。 任何人都知道如何使用 java 将其转换为等效的印地语文本
以下是我用来将字节数组转换为字节字符串的一段代码
public String byteArrayToByteString(byte[] arayValue, int size) {
byte ch = 0x00;
int i = 0;
if (arayValue == null || arayValue.length <= 0)
return null;
String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F" };
StringBuffer out = new StringBuffer();
while (i < size) {
ch = (byte) (arayValue[i] & 0xF0); // Strip off high nibble
ch = (byte) (ch >>> 4); // shift the bits down
ch = (byte) (ch & 0x0F); // must do this is high order bit is on!
out.append(pseudo[(int) ch]); // convert the nibble to a String
// Character
ch = (byte) (arayValue[i] & 0x0F); // Strip off low nibble
out.append(pseudo[(int) ch]); // convert the nibble to a String
// Character
i++;
}
String rslt = new String(out);
return rslt;
}
如果这有助于找到解决方案,请告诉我
编辑:
它是 UTF-16 编码,receivedText 字符串中的字符是印地语字符的扩展 ASCII 形式
新编辑
我有新角色
String value = "?®Á?Ƕ ¡??°¿¯¾";
印地语中的मुकेश和印地语中的dangaria。谷歌翻译器不会翻译印地语的 dangaria,所以我无法为您提供印地语版本。
我与正在编码的人交谈,他说他在编码之前从输入中删除了 2 位,即如果 \u0905 表示印地语中的 अ,那么他从输入中删除了 \u09 并将剩余的 05 转换为扩展的十六进制形式。
所以我提供给你的新输入字符串以上述解释的形式被解码。即 \u09 被删除,其余部分被转换为扩展 ascii,然后使用 USB 发送到设备。
如果这个解释能帮助你找到解决方案,请告诉我
【问题讨论】:
-
如果是 Java 字符串,则为 Unicode (UTF-16)。如果是其他字符串,则为损坏的字符串。展示如何将设备中的字节转换为字符串。
-
实际上这个字符串是从他们用来显示印地语文本的硬件接收的,我认为它是一个 UTF-16 文本,但我不知道如何转换它。我以字节数组的形式收到它,然后将其转换为字符串
-
您也可以创建自己的本地对象并使用它:docs.oracle.com/javase/tutorial/i18n/locale/create.html
-
-
你能显示接收到的字符串实际上应该是什么样子吗?这样可以更轻松地找到从一个到另一个的转化。
标签: java conventions extended-ascii