|
java版的.
主要生成的格式如下:
- wangdachui
- wdc
- wangdac
- wdachui
- wang.dachui
- dachui.wang
- dc.wang
- wang.dc
复制代码 支持多行姓名批量生成
软件下载地址:
没有你的规则?没关系,下面是源码,自己改改就有了..
源码:
HuoQuPinYin.java
- package com.zidian;
- import java.util.ArrayList;
- import java.util.List;
- import net.sourceforge.pinyin4j.PinyinHelper;
- import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
- import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
- import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
- import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
- /**
- * 拼音工具
- *
- * @author ceo@tom.com
- */
- public class HuoQuPinYin {
- /**
- * 获取汉字串拼音首字母,英文字符不变
- *
- * @param chinese 汉字串
- * @return 汉语拼音首字母
- */
- public static List cn2FirstSpell(String chinese) {
- List list=new ArrayList();
- 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) {
- list.add(_t[0].charAt(0));
- }
- } catch (BadHanyuPinyinOutputFormatCombination e) {
- return list;
- }
- } else {
- list.add(arr[i]);
- }
- }
- return list;
- }
- /**
- * 获取汉字串拼音,英文字符不变
- *
- * @param chinese 汉字串
- * @return 汉语拼音
- */
- public static List cn2Spell(String chinese) {
- List list =new ArrayList();
- if(chinese==null || chinese.equals("")){
- return list;
- }else{
- 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[] str=PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat);
- if(str==null || str.length==0){
- break;
- }
- list.add(PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat)[0]);
- } catch (BadHanyuPinyinOutputFormatCombination e) {
- break;
- }
- } else {
- list.add(arr[i]);
- }
- }
- return list;
- }
- }
-
- }
复制代码
ZiDian.java
项目附带jar包下载地址:
链接:http://share.weiyun.com/47540cd8f24ca6eca3a75709866f0c3d (密码:SXNX)
|
|