取得姓氏的拼音索引

import java.io.UnsupportedEncodingException;

class ChineseConvert {
 public String ChineseCap(String ChineseStr) {
  byte[] ZW = new byte[2];
  long ChineseStr_int;
  String CharStr, ChinaStr = "";
  CharStr = ChineseStr.substring(0, 1).toString();
  try {
   ZW = CharStr.getBytes("gb2312");
  } catch (UnsupportedEncodingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  // 得到汉字符的字节数组
  int hightByte = 256 + ZW[0];  
        int lowByte = 256 + ZW[1];  
  ChineseStr_int = (256 * hightByte + lowByte) - 256 * 256; 
  if ((ChineseStr_int >= -20319) && (ChineseStr_int <= -20292)) {
   ChinaStr = "A";
  } else if ((ChineseStr_int >= -20283)
    && (ChineseStr_int <= -19776)) {
   ChinaStr = "B";
  } else if ((ChineseStr_int >= -19775)
    && (ChineseStr_int <= -19224)) {
   ChinaStr = "C";

  } else if ((ChineseStr_int >= -19223)
    && (ChineseStr_int <= -18711)) {
   ChinaStr = "D";
  } else if ((ChineseStr_int >= -18710)
    && (ChineseStr_int <= -18527)) {
   ChinaStr = "E";
  } else if ((ChineseStr_int >= -18526)
    && (ChineseStr_int <= -18240)) {
   ChinaStr = "F";
  } else if ((ChineseStr_int >= -18239)
    && (ChineseStr_int <= -17923)) {
   ChinaStr = "G";
  } else if ((ChineseStr_int >= -17922)
    && (ChineseStr_int <= -17418)) {
   ChinaStr = "H";
  }
  else if ((ChineseStr_int >= -17417)
    && (ChineseStr_int <= -16475)) {
   ChinaStr = "J";
  } else if ((ChineseStr_int >= -16474)
    && (ChineseStr_int <= -16213)) {

   ChinaStr = "K";
  } else if ((ChineseStr_int >= -16212)
    && (ChineseStr_int <= -15641)) {
   ChinaStr = "L";
  } else if ((ChineseStr_int >= -15640)
    && (ChineseStr_int <= -15166)) {
   ChinaStr = "M";
  }
  else if ((ChineseStr_int >= -15165)
    && (ChineseStr_int <= -14923)) {
   ChinaStr = "N";
  } else if ((ChineseStr_int >= -14922)
    && (ChineseStr_int <= -14915)) {
   ChinaStr = "O";
  } else if ((ChineseStr_int >= -14914)
    && (ChineseStr_int <= -14631)) {
   ChinaStr = "P";

  } else if ((ChineseStr_int >= -14630)
    && (ChineseStr_int <= -14150)) {
   ChinaStr = "Q";
  }
  else if ((ChineseStr_int >= -14149)
    && (ChineseStr_int <= -14091)) {
   ChinaStr = "R";
  } else if ((ChineseStr_int >= -14090)
    && (ChineseStr_int <= -13319)) {
   ChinaStr = "S";
  } else if ((ChineseStr_int >= -13318)
    && (ChineseStr_int <= -12839)) {
   ChinaStr = "T";
  } else if ((ChineseStr_int >= -12838)
    && (ChineseStr_int <= -12557)) {
   ChinaStr = "W";
  } else if ((ChineseStr_int >= -12556)
    && (ChineseStr_int <= -11848)) {
   ChinaStr = "X";
  } else if ((ChineseStr_int >= -11847)
    && (ChineseStr_int <= -11056)) {
   ChinaStr = "Y";
  } else if (ChineseStr_int >= -11055)
    {
   ChinaStr = "Z";
  }
  return ChinaStr;
 }
}

public class IndexTest {
 //输入汉字字符串索引拼音的首字母2008年03月23日 星期日 21:33
 public static void main(String[] args) {
  ChineseConvert cc = new ChineseConvert();
  String[] idx = {"啊啊","毕福剑","朝阳","郑亮","强","留"};
  for(int i=0;i<idx.length;i++){
   System.out.println(i+"---"+cc.ChineseCap(idx[i]));
  }

      
 }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值