java如何获取笔画
1、java如何获取笔画,是通过查GB2312的字符集的笔划列表。下面给出源代码。

2、 public int getStrokeCount(char charcator) {
byte[] bytes = (String.valueOf(charcator)).getBytes();
if (bytes == || bytes.length > 2 || bytes.length <= 0) {
// 错误引用,非合法字符
return 0;
}
if (bytes.length == 1) {
// 英文字符
return 0;
}
if (bytes.length == 2) {
// 中文字符
int highByte = 256 + bytes[0];
int lowByte = 256 + bytes[1];
return GetGB2312StrokeCountM(highByte, lowByte);
}
// 未知错误
return 0;
}
/// <summary>
/// 获取字符串中所有汉字的笔画总和
/// </summary>
/// <param name="cnWords">字符串</param>
/// <returns></returns>
public int GetStrokeCount(String Words){

3、 //去除非中文
char[] words = Words.toCharArray();
int count = 0;
for (int i = 0; i < words.length; i++)
{
int returnCount= getStrokeCount(words[i]);
if (returnCount > 0)
{
count += returnCount;
}
}
return count;
}

4、 /// <summary>
/// 通过编码计算得到该汉字的偏移量,通过偏移量再在上面的笔画列表中
/// 得到该汉字的笔画数.
/// </summary>
/// <param name="c1"></param>
/// <param name="c2"></param>
/// <returns></returns>

5、 public static int GetGB2312StrokeCountM(int c1, int c2)
{
int OffSet;
if (c1 < 0xB0 || c1 > 0xF7 || c2 < 0xA1 || c2 > 0xFE)
{
// 不是一个有效的GB2312汉字字符
return -1;
}
OffSet = (c1 - 0xB0) * (0xFE - 0xA0) + (c2 - 0xA1);
return gb2312_stroke_count[OffSet];
}
/// <summary>
/// GB2312的字符集的笔划列表,可以参考gb2312字符全集
/// </summary>
//
