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));
        }
    }

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

  • 相关阅读:
    php 类 成员变量 $this->name='abc'
    php类的实现
    php 生成类的对象 $a=new test();
    php 对象的执行
    php 对象调用方法
    php 连接字符串. ZEND_ASSIGN_CONCAT/ZEND_CONCAT原理
    function 的声明
    vim用法
    ubuntn系统下将文件拷贝到优盘中及挂载概念理解
    windows远程连接linux-安装xfce界面,ubuntn添加新用户
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/15362548.html
Copyright © 2011-2022 走看看