zoukankan      html  css  js  c++  java
  • java转换汉字为首字母搜索,

    参阅:

    https://www.cnblogs.com/liangblog/p/13825427.html

    maven

     <dependencies>
        <dependency>
            <groupId>com.github.stuxuhai</groupId>
            <artifactId>jpinyin</artifactId>
            <version>1.1.8</version>
        </dependency>
    import com.github.stuxuhai.jpinyin.ChineseHelper;
    import com.github.stuxuhai.jpinyin.PinyinFormat;
    import com.github.stuxuhai.jpinyin.PinyinHelper;
    
    
    
    
    public class PinyinHelperTest {
    
        /**
         * 转换为每个汉字对应拼音首字母字符串
         * @param pinYinStr 需转换的汉字
         * @return 拼音字符串
         */
        public String changeToGetShortPinYin(String pinYinStr){
    
            String tempStr = null;
    
            try
            {
                tempStr = PinyinHelper.getShortPinyin(pinYinStr);
            } catch (Exception e)
            {
                e.printStackTrace();
            }
            return tempStr;
    
        }
    
        public boolean checkPinYin(char pinYinStr){
    
            boolean check  = false;
            try
            {
                check = PinyinHelper.hasMultiPinyin(pinYinStr);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return check;
        }
    
        public static void main(String[] args) {
            String str = "大夫";
            PinyinHelperTest jp = new PinyinHelperTest();
    //        System.out.println(jp.changeToMarkPinYin(str));
    //        System.out.println(jp.changeToTonePinYin(str)); //有空格
    //        System.out.println(jp.changeToSimplified(str));
            System.out.println(jp.checkPinYin(''));
    
            System.out.println(jp.changeToGetShortPinYin(str));
        }
    }

    建议在数据库中,增加一个字段,作为首字母的存储。

  • 相关阅读:
    3513: [MUTC2013]idiots
    ELK+Filebeat+Kafka+ZooKeeper 构建海量日志分析平台(elk5.2+filebeat2.11)
    【python全栈开发】初识python
    SQL疑难问题
    费用分摊问题
    透过现象看本质
    关于python3round与float的四省五入精度的问题
    Win10下VSCode安装PlantUML
    安装pymssql
    ensorFlow的安装
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/15362548.html
Copyright © 2011-2022 走看看