Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate Pinyin first Spelling and five-stroke Code of Chinese characters in Java

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to generate pinyin initial spelling and five-stroke code of Chinese characters in Java. It is very detailed and has certain reference value. Interested friends must finish reading it!

Chinese characters generate pinyin first spelling and five-stroke code

Recently, we are about to start a new project. I see in the requirements report that there is a need to generate pinyin initials and five-stroke codes. I have also found a lot of them on the Internet, but the results are not satisfactory. There are few cases of generating five-stroke codes and the codes are all from seven or eight years ago. There is an exception in execution. All right, let's get started.

Pinyin first spelling

To generate the case of Pinyin, you need to introduce pinyin4j, a jar package dependency.

Com.belerweb pinyin4j 2.5.1

Pinyin first spelling lowercase

Public static String toFirstChar (String str) {String context = ""; for (int j = 0; j

< str.length(); j++) { char word = str.charAt(j); String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word); if (pinyinArray != null) { context += pinyinArray[0].charAt(0); } else { context += word; } } return context; } 拼音首拼大写 public static String toBigFirstChar(String chines) { String pinyinName = ""; char[] nameChar = chines.toCharArray(); HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE); defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); for (int i = 0; i < nameChar.length; i++) { if (nameChar[i] >

< str.length(); i++) { char temp1 = str.charAt(i); int asciicode = (int)temp1; //如果是254以内的ASCII 表示是西文字母和字符,直接显示,无需翻译 if (asciicode >

= 1 & & asciicode

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report