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. Customizing Zend Studio Using the Welcome Page

    Customizing Zend Studio Using the Welcome Page Zend Studio enables you to add or remove plugins from ...

  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. cocos2d-x -------之笔记篇 环境的安装

    cocos2d-x -------之笔记篇 环境的安装 使用到的工具有VS2010  cygwin android-NDK eclipse android SDK 1.首先是android相关环境的安 ...

  4. linux的nohup命令的用法。

    在应用Unix/Linux时,我们一般想让某个程序在后台运行,于是我们将常会 用 & 在程序结尾来让程序自动运行.比如我们要运行mysql在后台: /usr/local/mysql/bin/m ...

  5. WIX 学习笔记- 1 简介

    一个项目 Code Complete 后,程序员们欢欣鼓舞,以为事情到此结束,可以 Happy 了.其实 Code Complete 五十之于百里.一个没有运行在设备上,为人们创造价值的项目是注定失败 ...

  6. linux关闭防火墙方法

    在关闭防火墙之前需要查看防火墙的状态,可以使用service iptables status命令来查看,确定防火墙是否开启再来进行关闭操作. 如果想临时开启防火墙使用命令service iptable ...

  7. 解决Qt程序发布时中文乱码问题(通过QApplication.addLibraryPath加载QTextCodec插件)

    Qt程序的文字编码,是通过插件来解决的,所以我们发布的时候需要把相应的插件也发布出去,在开发者电脑上程序会自动从插件目录加载到插件,但是如果发布给别的电脑使用,需要手动指定插件路径,如下所示: int ...

  8. ViewPager + HorizontalScrollView 实现可滚动的标签栏

    这是一个可滑动的标签栏的自定义控件,参考此文章http://blog.csdn.net/fx_sky/article/details/8990573,我将主要的功能整合成一个类,配上2个特定的布局即可 ...

  9. 去英国Savile Row 做件私人定制手工西装_GQ男士网

    去英国Savile Row 做件私人定制手工西装_GQ男士网 去英国Savile Row 做件私人定制手工西装

  10. js 事件之 createEvent、dispatchEvent

    //document上绑定自定义事件ondataavailable document.addEventListener('customevent', function(event) { alert(e ...