获取中文的首字母demo
import net.sourceforge.pinyin4j.PinyinHelper;
/**
*
* @Title: getPinYinHeadChar
* @Description: TODO 获取中文的首字母
* @param str 传入的中文参数
* @return * @return: String
*/
public static String getPinYinHeadChar(String str) {
String convert = "";
for (int j = 0; j < str.length(); j++) {
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null) {
convert += pinyinArray[0].charAt(0);
} else {
convert += word;
}
}
return convert;
}
测试:
System.out.println(PinYinUtil.getPinYinHeadChar("我比较"));===》wbj
获取中文的首字母demo的更多相关文章
- sqlservice 查询该字段的值是否为数字、不包含a-z字母、获取中文的首字母
select zjm from xskh where guid_yw='e6ee44f3-98ab-4446-bd9b-db2e525d3b24' and zjm not like '%[ABCDE ...
- excel 获取中文拼音首字母
excel 获取中文拼音首字母 CreateTime--2018年5月31日08:50:42 Author:Marydon 1.情景展示 想要获取姓名的拼音首字母 2.实现方式 通过使用excel ...
- [Python] Python 获取中文的首字母 和 全部拼音首字母
Python 获取中文的首字母 和 全部拼音首字母 代码如下: import pinyin def getStrAllAplha(str): return pinyin.get_initial(str ...
- JS获取中文拼音首字母,并通过拼音首字母高速查找页面内的中文内容
实现效果: 图一: 图二: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGVzdGNzX2Ru/font/5a6L5L2T/fontsize/400/f ...
- python 获取中文拼音首字母;判断文件夹是否存在
1.如何获取中文字符串的首字母 import pinyin #输入name def get_pinyin_first_alpha(name): return "".join([i[ ...
- php 获取中文字符串首字母
<?php $limit=array( //gb2312 拼音排序 array(45217,45252), //A array(45253,45760), //B array(45761,463 ...
- java获取中文拼音首字母
import net.sourceforge.pinyin4j.PinyinHelper; public class PinyinHelperUtil { /** * 得到中文首字母(中国 -> ...
- PHP获取中文汉字首字母方法
function getFirstLetter($str){ $fchar = ord($str{0}); if($fchar >= ord("A") and $fchar ...
- php 中文字符串首字母的获取函数
这篇文章介绍了php 中文字符串首字母的获取函数,有需要的朋友可以参考一下 function chineseFirst($str) { $str= iconv("UTF-8",&q ...
随机推荐
- python判断key是否存在
d = {: , : , : , : , : , : } def is_key_present(x): if x in d: print('Key is present in the dictiona ...
- [osgearth]osgearth原数据获取途径
Help us add useful sources of Free data to this list. Raster data ReadyMap.org - Free 15m imagery, e ...
- mybatis之org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'time' in 'class java.lang.String'
mybatis接口 List<String> getUsedCate(String time); 配置文件 <select id="getUsedCate" pa ...
- hdu4549矩阵快速幂+费马小定理
转移矩阵很容易求就是|0 1|,第一项是|0| |1 1| |1| 然后直接矩阵快速幂,要用到费马小定理 :假如p是质数,且gcd(a,p)=1,那么 a(p-1)≡1(m ...
- Leetcode 64
class Solution { public: int minPathSum(vector<vector<int>>& grid) { int n = grid.si ...
- Beta阶段第2周/共2周 Scrum立会报告+燃尽图 14
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制:https://git.coding.net/liuyy08 ...
- HDU 2485
http://acm.hdu.edu.cn/showproblem.php?pid=2485 n个车站,m条边,两边之间费用为1,问最少摧毁多少车站,使得1-n无法在k时间内到达 将2-(n-1)每个 ...
- Jmeter-Logic Controllers(逻辑控制器)
Critical Section Controller(临界区控制器) 参考:http://www.cnblogs.com/yanzhe/p/7729984.html ForEach Controll ...
- 在create-react-app创建的项目下允许函数绑定运算符
前话 React的函数绑定一致是个问题,主要有下面几种方式: 事件处理器动态绑定 export default class Com extends React.Component { render() ...
- MyBatis_Study_002(进阶,增删改查)
源码:https://github.com/carryLess/mbtsstd-002.git 1.主配置文件 <?xml version="1.0" encoding=&q ...