Java: Pinying 拼音

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * encoding: utf-8
 * 版权所有 2023 涂聚文有限公司
 * 许可信息查看:
 * 描述:https://github.com/houbb/pinyin
 * https://mvnrepository.com/artifact/com.github.stuxuhai/jpinyin/1.1.8
 * https://github.com/ranLee1/jpinyin
 * https://github.com/shenkevin/jpinyin
 * https://github.com/hellokaton/TinyPinyin  速度快
 * # Author    : geovindu,Geovin Du 涂聚文.
 * # IDE       : IntelliJ IDEA 2023.1 Java 17
 * # Datetime  : 2023 - 2023/12/16 - 6:18
 * # User      : geovindu
 * # Product   : IntelliJ IDEA
 * # Project   : javademo
 * # File      : PinyinHelper.java  类
 * # explain   : 学习
 **/
 
package Common;
 
import java.util.Random;
import java.lang.String;
import java.io.UnsupportedEncodingException;
import java.util.Random;
//import opensource.jpinyin.ChineseHelper;
//import opensource.jpinyin.PinyinFormat;
//import opensource.jpinyin.PinyinHelper;
import com.github.stuxuhai.jpinyin.ChineseHelper;
import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import com.github.stuxuhai.jpinyin.*;
 
/**
 * 汉字转拼音类
 */
public class DuPinyinHelper {
 
    /**
     *有声调的拼音
     * @param ChineseWord 中国的首都是北京
     * @return
     */
    public  static String ShenTiao(String ChineseWord)
    {
        String pin="";
        try {
 
             
            //带音标   zhōng,guó,de,shǒu,dū,shì,běi,jīng
            pin=com.github.stuxuhai.jpinyin.PinyinHelper.convertToPinyinString(ChineseWord,",",PinyinFormat.WITH_TONE_MARK);
             
 
 
   
 
            return  pin;
 
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
            return  null;
        }
 
    }
 
    /**
     * 用数字标的拼音
     * @param ChineseWord
     * @return
     */
    public static String ShengtiaoNum(String ChineseWord)
    {
        String pin="";
        try {
 
 
            //用数字代替音标   zhong1,guo2,de5,shou3,du1,shi4,bei3,jing1
            System.out.println(com.github.stuxuhai.jpinyin.PinyinHelper.convertToPinyinString(ChineseWord,",",PinyinFormat.WITH_TONE_NUMBER));
            pin=com.github.stuxuhai.jpinyin.PinyinHelper.convertToPinyinString(ChineseWord,",",PinyinFormat.WITH_TONE_NUMBER);
            //不带音标  zhong,guo,de,shou,du,shi,bei,jing
           // System.out.println(com.github.stuxuhai.jpinyin.PinyinHelper.convertToPinyinString(ChineseWord, ",", PinyinFormat.WITHOUT_TONE));
           // pin=com.github.stuxuhai.jpinyin.PinyinHelper.convertToPinyinString(ChineseWord, ",", PinyinFormat.WITHOUT_TONE);
            return  pin;
 
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
            return  null;
        }
    }
 
    /**
     * 无声调的拼音
     * @param ChineseWord
     * @return
     */
    public static String NoShengtiaoNum(String ChineseWord)
    {
        String pin="";
        try {
 
 
            //不带音标  zhong,guo,de,shou,du,shi,bei,jing
            // System.out.println(com.github.stuxuhai.jpinyin.PinyinHelper.convertToPinyinString(ChineseWord, ",", PinyinFormat.WITHOUT_TONE));
             pin=com.github.stuxuhai.jpinyin.PinyinHelper.convertToPinyinString(ChineseWord, ",", PinyinFormat.WITHOUT_TONE);
            return  pin;
 
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
            return  null;
        }
    }
    /**
     * 小写首字母
     * @param ChineseWord
     * @return
     */
    public static String ShengMuLower(String ChineseWord)
    {
        String pin="";
        try {
 
            //System.out.println(com.github.stuxuhai.jpinyin.PinyinHelper.getShortPinyin(ChineseWord));//输出拼音首字母 小写 zgdsdsbj
            pin=com.github.stuxuhai.jpinyin.PinyinHelper.getShortPinyin(ChineseWord).toLowerCase();
            return  pin;
 
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
            return  null;
        }
    }
 
    /**
     * 大写首字母
     * @param ChineseWord
     * @return
     */
    public static String ShengMuUpper(String ChineseWord)
    {
        String pin="";
        try {
 
            //System.out.println(com.github.stuxuhai.jpinyin.PinyinHelper.getShortPinyin(ChineseWord));//输出拼音首字母
            pin=com.github.stuxuhai.jpinyin.PinyinHelper.getShortPinyin(ChineseWord).toUpperCase();
            return  pin;
 
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
            return  null;
        }
    }
 
}

  

调用:

1
DuPinyinHelper.ShenTiao("我是涂聚文,江西人");

  

输出:

 

posted @   ®Geovin Du Dream Park™  阅读(41)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示