Android通讯录开发之取得姓名首字母实现简拼搜索

// GB2312码汉字区间十进制表示

private static int[] table = new int[27];

// 对应首字母区间表

private static char[] initialtable = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’,

‘h’, ‘h’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’,

‘t’, ‘t’, ‘w’, ‘x’, ‘y’, ‘z’, };

// 初始化

static {

for (int i = 0; i < 26; i++) {

table[i] = gbValue(chartable[i]);// 得到GB2312码的首字母区间端点表,十进制。

}

table[26] = END;// 区间表结尾

}

/**

  • 根据一个包含汉字的字符串返回一个汉字拼音首字母的字符串 最重要的一个方法,思路如下:一个个字符读入、判断、输出

*/

public static String getFirstLetter(String sourceStr) {

String result = “”;

String str = sourceStr.toLowerCase();

int StrLength = str.length();

int i;

try {

for (i = 0; i < StrLength; i++) {

result += Char2Initial(str.charAt(i));<

  • 13
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值