Convert Chinese strings to English strings

Apply pinyin4j.jar

public static class ConvertChineseToPinyin {

public static String getPingYin(String src) {
   char[] t1 = null;
   t1 = src.toCharArray();
   String[] t2 = new String[t1.length];
   HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
   t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
   t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
   t3.setVCharType(HanyuPinyinVCharType.WITH_V);
   String t4 = "";
   int t0 = t1.length;
   try {
    for (int i = 0; i < t0; i++) {
     if (java.lang.Character.toString(t1[i]).matches(
       "[\\u4E00-\\u9FA5]+")) {
      t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
      t4 += t2[0];
     } else {
      t4 += java.lang.Character.toString(t1[i]);
     }
    }
    return t4;
   } catch (Exception e) {
    e.printStackTrace();
   }
   return t4;
  }

public static String cn2FirstSpell(String chinese) {
   StringBuffer pybf = new StringBuffer();
   char[] arr = chinese.toCharArray();
   HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
   defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
   defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
   for (int i = 0; i < arr.length; i++) {
    if (arr[i] > 128) {
     try {
      String[] _t = PinyinHelper.toHanyuPinyinStringArray(
        arr[i], defaultFormat);
      if (_t != null) {
       pybf.append(_t[0].charAt(0));
      }
     } catch (Exception e) {
      e.printStackTrace();
     }
    } else {
     pybf.append(arr[i]);
    }
   }
   return pybf.toString().replaceAll("\\W", "").trim();

}
 }

Android API for sorting Chinese strings

Comparator comparator = Collator
     .getInstance(java.util.Locale.CHINA);
   Collections.sort(userRealNames, comparator);

//userRealNames is ArrayList<String>

Check Chinese characters

private static final boolean isChinese(char c) {
  Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
  if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
    || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
    || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
    || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
    || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
    || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
   return true;
  }
  return false;
 }

(Android) Chinese Character的更多相关文章

  1. IEF could not decode Chinese character in IE history well

    My friend is working on some case, and she looks not in the mood. I ask her what's going on. She wan ...

  2. EnCase v7 could not recognize Chinese character folder names / file names on Linux Platform

    Last week my friend brought me an evidence file duplicated from a Linux server, which distribution i ...

  3. GitHub & puppeteer & Chinese character & bug

    GitHub & puppeteer & Chinese character & bug https://github.com/GoogleChrome/puppeteer/b ...

  4. csharp: Converting chinese character to Unicode

    Function chinese2unicode(Str) Dim Str_one:Str_one = "" Dim Str_unicode:Str_unicode = " ...

  5. Android 汉字转拼音之工具篇

    /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Versi ...

  6. Note over Chinese Encodings

    I been confused years ago. Till recently I collected my thoughts together, and now I am clear about ...

  7. 英语单词character

    来源——tr帮助说明 TR() User Commands TR() NAME tr - translate or delete characters SYNOPSIS tr [OPTION]... ...

  8. Total Commander 8.52 Beta 1

    Total Commander 8.52 Beta 1http://www.ghisler.com/852_b1.php 10.08.15 Release Total Commander 8.52 b ...

  9. 优化后的 google提供的汉字转拼音类(针对某些htc等手机的不兼容情况)

    /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Versi ...

随机推荐

  1. JavaScript装逼指南

    如何写JavaScript才能逼格更高呢?怎样才能组织JavaScript才能让别人一眼看出你不简单呢?是否很期待别人在看完你的代码之后感叹一句“原来还可以这样写”呢?下面列出一些在JavaScrip ...

  2. Viewing the Raw SQL Statement(xcode で)

    Thanks to Core Data. Even without learning SQL and database, you’re able to perform create, select, ...

  3. src 和 href 的区别

    因为理解不深,到写外部加载Javascript文件或者css文件的时候总是需要去找个例子,这样可不好.现在总结下 href 属性规定被链接文档的位置(URL). href是hyperrefresh的缩 ...

  4. MYSQL 引擎的情况

    方法 1: show engine innodb status; ------------------------------------------------------------------- ...

  5. ETL中的数据增量抽取机制

    ETL中的数据增量抽取机制 (     增量抽取是数据仓库ETL(extraction,transformation,loading,数据的抽取.转换和装载)实施过程中需要重点考虑的问 题.在ETL过 ...

  6. Oracle EBS-SQL (GL-5):从发票追溯到接收

    SELECT destination_type_code, distribution_line_number, line_type, amount,vat_code, tax_code_id, tax ...

  7. js类方法,对象方法,原型的理解(转)

    function People(name) { this.name=name; //对象方法 this.Introduce=function(){ alert("My name is &qu ...

  8. Android setTag IllegalArgumentException

    E/AndroidRuntime(19480): java.lang.IllegalArgumentException: The key must be an application-specific ...

  9. javaio学习笔记-字符流类(2)

    1.java.io包中的字符流类-FileReader和FileWriter: BufferedReader:缓存的输入字符流; BufferedWriter:缓存的输出字符流; FileReader ...

  10. frameset常用属性

    框架是网页画面分成几个框窗(不同的窗口对应不同页面以几个网页的形式显示),同时取得多个 src的地址.页面所有框架标记需要放在一个总起的 html 档,这个档案只记录了该框架如何分割 ,不会显示任何资 ...