package com.zl;

import java.io.UnsupportedEncodingException;

public class Test12 {

    public static void main(String[] args) {
String jianpin = toJianPin("你好");
System.out.println(jianpin);
} /**
*
* toJP方法:汉字转成简拼 <br/>
* <br/>
*
* @param c
* @return
* @exception
*/
public static String toJianPin(String c) { char[] chars = c.toCharArray(); StringBuffer sb = new StringBuffer(""); for (int i = 0; i < chars.length; i++) {
sb.append(getJP(chars[i]));
}
String aa = sb.toString();
return aa.toUpperCase();
}
public static String getJP(char c) {
byte[] array = new byte[2];
try {
array = String.valueOf(c).getBytes("gbk");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (array.length < 2)
return String.valueOf(c);
int i = (short) (array[0] + 256) * 256 + ((short) (array[1] + 256));
if (i < 0xB0A1)
return String.valueOf(c);
if (i < 0xB0C5)
return "a";
if (i < 0xB2C1)
return "b";
if (i < 0xB4EE)
return "c";
if (i < 0xB6EA)
return "d";
if (i < 0xB7A2)
return "e";
if (i < 0xB8C1)
return "f";
if (i < 0xB9FE)
return "g";
if (i < 0xBBF7)
return "h";
if (i < 0xBFA6)
return "j";
if (i < 0xC0AC)
return "k";
if (i < 0xC2E8)
return "l";
if (i < 0xC4C3)
return "m";
if (i < 0xC5B6)
return "n";
if (i < 0xC5BE)
return "o";
if (i < 0xC6DA)
return "p";
if (i < 0xC8BB)
return "q";
if (i < 0xC8F6)
return "r";
if (i < 0xCBFA)
return "s";
if (i < 0xCDDA)
return "t";
if (i < 0xCEF4)
return "w";
if (i < 0xD1B9)
return "x";
if (i < 0xD4D1)
return "y";
if (i < 0xD7FA)
return "z";
return String.valueOf(c); } }

输入一段汉字可以获得首字母简拼的java代码的更多相关文章

  1. c#汉字转拼音首字母全拼支持多音字

    1.首先在NuGet安装pingyinConverter 2.下载-安装-引用ChineseChar.dll到项目中 官网了解:http://www.microsoft.com/zh-cn/downl ...

  2. [功能帮助类] C#取汉字拼音的首字母PinYin帮助类 (转载)

    点击下载 PinYin.rar 主要功能就是取汉字拼音的首字母,只要你输入一个汉字,或者是多个汉字就会取出相应的道字母,主要是方便查询使用的 /// <summary> /// 编 码 人 ...

  3. 汉字转拼音首字母的java实现

    工作中经常会遇到的一些排序问题,比如 按汉字的拼音首字母排序,比如人名排序等,就要用到下面的方法了,思路: 1. 获得汉字 2. 将汉字转换成首字母,并记录下(必要时保存到数据库) 3. 按首字母进行 ...

  4. C# 汉字转拼音 取汉字拼音的首字母

    using System.Text.RegularExpressions; namespace DotNet.Utilities { /// <summary> /// 汉字转拼音类 // ...

  5. MySQL数据库获取多个汉字拼音的首字母函数

    需求简介:最近的一个项目,想实现如下图所示的显示效果.很明显,如果能够获取对应的汉字词组中每个汉字的拼音首字母就可以实现了,如果是固定的几组汉字,人为的拼一下就可以 了,不过项目中有多处功能需要这个效 ...

  6. (转载)delphi中获取汉字的拼音首字母

    delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...

  7. SqlServer 汉字转换拼音首字母函数

    CREATE function [dbo].[Func_GetPY](@str nvarchar(4000))returns nvarchar(4000)asbegin set @str=RTRIM( ...

  8. 简单测试--C#实现中文汉字转拼音首字母

    第一种: 这个是自己写的比较简单的实现方法,要做汉字转拼音首字母,首先应该有一个存储首字母的数组,然后将要转拼音码的汉字与每个首字母开头的第一个汉字即“最小”的汉字作比较,这里的最小指的是按拼音规则比 ...

  9. sql获取汉字的拼音首字母的函数

    ql获取汉字的拼音首字母   if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...

随机推荐

  1. [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: URLError: <urlopen error [Errno 10061] Connection refused>

    [ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: URLError: <urlopen error ...

  2. FTP故障排除

    1,ping 检查 IP是否通 禁PING可以使用TCPING 2,服务器端被动模式设置,可设置固定端口号,保证防火墙上该端口畅通 浏览器默认是主动模式 3,使用FLASHFXP软件可以监测到数据端口 ...

  3. String的Split使用方法(以特定字符分隔,提取所需信息)

    此处复制一串以空格分隔的数字,提取数字进行排序 int[] a = new int[10]; string input = Console.ReadLine();//获取用户输入的字符串 char[] ...

  4. tx2--开机启动

    TX2上电自动开机 参考:http://121.42.13.250/?p=168 问题描述 Jetson TX2在接通电源后,按下板子上的PWOER BTN开机键(S4)后,便能够正常启动.但这对于一 ...

  5. Codeforces 437D 贪心+并查集

    这个题目让我想起了上次在湘潭赛的那道跪死了的题.也是最值问题,这个也是,有n个动物园 每个都有权值 然后被m条路径相连接,保证图是连通的,然后求所有的p[i][j]之和.i,j为任意两个zoo,pij ...

  6. ucosiii 学习笔记

    OSTaskCreate 的参数中有一个 void *p_ext,这个参数用来传递额外的信息,可以用来传递数组,结构体等等. AppTaskStart --> CPU_Init --> C ...

  7. promise核心技术 1 实例对象/函数对象

    一个程序员要在看到代码的语法同时判断数据类型 知道语法是基础  基础才能延伸功能 //一行代码 a()[0]() // a() 首先推断出a是一个函数 //a()[0] 判断a函数的返回值是一个数组 ...

  8. torch.Tensor文档学习笔记

    A torch.Tensor is a multi-dimensional matrix containing elements of a single data type. 张量(torch.Ten ...

  9. python安装wordcloud、jieba,pyecharts

    1.安装wordcloud: 适用于无法使用pip install wordcloud安装的情况: 据python和windows 版本 到https://www.lfd.uci.edu/~gohlk ...

  10. BZOJ [HAOI2006]旅行comf

    题解:枚举最大边,然后对<=最大边的边做最大生成树,使最小边最大 #include<iostream> #include<cstdio> #include<cstr ...