a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 116|回复: 1

[基础知识] JAVA基础:java代码如何将汉字转换成拼音(2)

[复制链接]
发表于 2012-8-4 12:37:27 | 显示全部楼层 |阅读模式
 package com.sucre;   //所需导入的jar包在下侧下载: N  i" i6 q  U' {; h
  import net.sourceforge.pinyin4j.PinyinHelper;2 u" g  L  f; ?: a+ T7 ~
  import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;  O4 s& D9 O# J: n4 H2 w1 U3 G2 i
  import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;" \1 B- V1 l( u& e# ^
  import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
- T2 d  A3 W) ~% V) T6 O" P8 F  import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;- k5 y- \2 l6 ~+ d" m' @3 {
  import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;' O2 j6 ]3 L! B" b
  public class ChineseToEnglish
( X: G! Z" |0 ?; C0 }4 `# I4 x0 u: ^  O
  {
回复

使用道具 举报

 楼主| 发表于 2012-8-4 12:37:28 | 显示全部楼层

JAVA基础:java代码如何将汉字转换成拼音(2)

</p>  //------------------------将汉字转换为全拼-------------------------------
7 ~& ]5 {7 G8 t% V; p# V0 e- Y  public static String getPingYin(String src){2 R+ {: g( _/ S& w) [! H
  char[] t1 = null;
' R9 y+ P+ U1 B4 R- u2 w4 h/ h  t1=src.toCharArray();) c6 G) w3 P  O5 l- M* ?/ u
  String[] t2 = new String[t1.length];' c" Z/ E, g0 ?$ X$ h+ _
  HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
# ?! g+ {+ ^: z4 w) Q  t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
% |; h9 R- Y4 T. m6 A. D. `  t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
7 J/ I, t. l- \4 N; ^  t3.setVCharType(HanyuPinyinVCharType.WITH_V);
# ~& F7 c! _6 {( s! z& j  String t4="";
7 ~) r/ C1 @# B1 D3 ~3 e) A1 U  int t0=t1.length;
& P0 j# M3 C+ @4 l1 m7 V  try {6 G& {" U; p8 [; G+ r; v4 t

! J; }: _% I5 K0 x; U- `  for (int i=0;i
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-15 08:53 , Processed in 0.178525 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表