我在研究一个少数民族语言的程序,由于4.0以下的版本不支持这语言只能做一些复杂的过程。我用一个so文件成功把少数民族语言显示正常了,可是如果字符串包括英文字母或者数字那就乱了。          String str = "abcئۇيغۇرچە";
         StringBuffer buf = new StringBuffer(str);
         buf = buf.reverse(); 
         System.out.println(buf.toString());现在的解决方法是 反转字符串的时候让它编码在1536到1791之间的文字反转过来,其他的就不要反转。
我是个新手,所以不是很懂java和android,所以请大家帮我写个简单的代码。
我想实现的是 比如字符串为“你好abc”,我把他反转为“你好cba”就是把指定的字符串反转过来。指定的就是编码为1536-1791之间的字符串。

解决方案 »

  1.   

    试试看这种方式行否:
    为Android添加一门新语言
    http://www.cnblogs.com/melaniedeng/archive/2012/02/15/2353382.html
      

  2.   

    public static void main(String[] args) {
    String str = "abcئۇيغۇرچە";
    char[] c = str.toCharArray();
    sort(c);
    String out = new String(c);
    System.out.println(str);
    System.out.println(out);
    } private static void sort(char[] c) {
    int start = -1; // 需要反转部分的起始下标 不需要反转时设为-1
    boolean flag = false; // 是否是阿拉伯语字符的标志
    for (int i = 0; i < c.length; i++) {
    flag = isArabic(c[i]); // 判断当前字符是否是阿拉伯语字符
    if (start != -1 && !flag) { // 如果之前已经检测到了阿拉伯语字符 且当前字符不是阿拉伯语字符;
    reverse(c, start, i);
    start = -1;
    }
    if (start == -1 && flag) { // 如果之前未检测到阿拉伯语字符 且当前字符是阿拉伯语字符
    start = i;
    } }
    if (start != -1) {
    reverse(c, start, c.length);
    start = -1;
    }
    } /**
     * 将字符数组的指定部分反转
     * 
     * @param c 需要反转的字符串数组
     * @param start 需要反转部分的起始下标
     * @param end 需要反转部分的结束下标
     */
    private static void reverse(char[] in, int start, int end) {
    System.out.println("Do reverse between " + start + " , " + end);
    int n = (end - start) / 2; // 计算交换次数
    for (int i = 0; i < n; i++) { // 交换
    char t = in[start + i];
    in[start + i] = in[end - i - 1];
    in[end - i - 1] = t;
    }
    } /**
     * 判断输入的字符是否是阿拉伯字符
     * 
     * @param c 输入的字符
     * @return 是阿拉伯字符返回true 不是返回false
     */
    private static boolean isArabic(char c) {
    int u = c;
    if (0x0600 <= u && 0x06FF >= u) { // 如果是Unicode码表 阿拉伯文 0600-06FF区间
    return true;
    }
    if (0x0750 <= u && 0X077F >= u) { // 如果是Unicode码表 阿拉伯文补充 0750-077F区间
    return true;
    }
    return false;
    }
    输出结果:
    Do reverse between 3 , 11
    abcئۇيغۇرچە
    abcەچرۇغيۇئ看不懂阿拉伯文  不晓得对不对....