|
@@ -17,6 +17,12 @@ public class Cn2SpellUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //调用类时自动加载字典
|
|
|
+ static{
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ //字典设置
|
|
|
public static void init() {
|
|
|
Pinyin.init(Pinyin.newConfig()
|
|
|
.with(new PinyinMapDict() {
|
|
@@ -39,7 +45,6 @@ public class Cn2SpellUtil {
|
|
|
* @return 拼音
|
|
|
*/
|
|
|
public static String converterToFirstSpell(String chines) {
|
|
|
- init();
|
|
|
String pinyinName = "";
|
|
|
String pinyinRes = Pinyin.toPinyin(chines, "*××*");
|
|
|
if (StringUtil.isNotBlank(pinyinRes)){
|
|
@@ -82,7 +87,6 @@ public class Cn2SpellUtil {
|
|
|
* @return 拼音
|
|
|
*/
|
|
|
private static String converterToSpellByCaseType(String chines, Integer caseType) {
|
|
|
- init();
|
|
|
String pinyinName = "";
|
|
|
if (caseType.equals(2)) {
|
|
|
pinyinName = Pinyin.toPinyin(chines, "").toLowerCase();
|
|
@@ -94,19 +98,19 @@ public class Cn2SpellUtil {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
System.out.println("================首字母================");
|
|
|
- System.out.println(converterToFirstSpell("欢迎来到Java世界"));
|
|
|
- System.out.println(converterToFirstSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
|
|
|
- System.out.println(converterToFirstSpell("-"));
|
|
|
- System.out.println(converterToFirstSpell("𬌗-𧿹"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToFirstSpell("欢迎来到Java世界"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToFirstSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToFirstSpell("-"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToFirstSpell("𬌗-𧿹"));
|
|
|
System.out.println("================大写全拼================");
|
|
|
- System.out.println(converterToSpell("欢迎来到Java世界"));
|
|
|
- System.out.println(converterToSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
|
|
|
- System.out.println(converterToSpell("-"));
|
|
|
- System.out.println(converterToSpell("𬌗-𧿹"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpell("欢迎来到Java世界"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpell("11β-羟化酶缺陷症#11-羟化酶缺陷"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpell("-"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpell("𬌗-𧿹"));
|
|
|
System.out.println("================小写全拼================");
|
|
|
- System.out.println(converterToSpellLow("欢迎来到Java世界"));
|
|
|
- System.out.println(converterToSpellLow("11β-羟化酶缺陷症#11-羟化酶缺陷"));
|
|
|
- System.out.println(converterToSpellLow("-"));
|
|
|
- System.out.println(converterToSpellLow("𬌗-𧿹"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpellLow("欢迎来到Java世界"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpellLow("11β-羟化酶缺陷症#11-羟化酶缺陷"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpellLow("-"));
|
|
|
+ System.out.println(Cn2SpellUtil.converterToSpellLow("𬌗-𧿹"));
|
|
|
}
|
|
|
}
|