LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1406|回复: 7

此题如何考虑

[复制链接]
发表于 2004-6-11 13:09:05 | 显示全部楼层 |阅读模式
用java写个小程序,测试char c是否是ascii character. 提示:ASCII character只用最后7位bits。而JAVA里的character变量是16位元, 换句话说要测试这个字符的前9个bit都是0, 哪为可以提供一下考虑思路。。谢谢。
发表于 2004-6-11 14:28:32 | 显示全部楼层
你看看这个方法行不行:

java.lang.Character


isISOControl
public static boolean isISOControl(char ch)Determines if the specified character is an ISO control character. A character is considered to be an ISO control character if its code is in the range '\u0000' through '\u001F' or in the range '\u007F' through '\u009F'.

Parameters:
ch - the character to be tested.
Returns:
true if the character is an ISO control character; false otherwise.
Since:
1.1
See Also:
isSpaceChar(char), isWhitespace(char)
 楼主| 发表于 2004-6-11 14:31:51 | 显示全部楼层
如果用String里面的valueOF()将c转成hexadecimal然后再把里面每个digit加以测试你觉得呢?
发表于 2004-6-11 14:42:26 | 显示全部楼层
isUnicodeIdentifierPart
public static boolean isUnicodeIdentifierPart(char ch)Determines if the specified character may be part of a Unicode identifier as other than the first character.
A character may be part of a Unicode identifier if and only if one of the following statements is true:

it is a letter
it is a connecting punctuation character (such as '_')
it is a digit
it is a numeric letter (such as a Roman numeral character)
it is a combining mark
it is a non-spacing mark
isIdentifierIgnorable returns true for this character.

Parameters:
ch - the character to be tested.
Returns:
true if the character may be part of a Unicode identifier; false otherwise.
Since:
1.1
See Also:
isIdentifierIgnorable(char), isJavaIdentifierPart(char), isLetterOrDigit(char), isUnicodeIdentifierStart(char)


java.lang.Character里面应该有你想要的方法。
 楼主| 发表于 2004-6-11 14:47:19 | 显示全部楼层
但我不想用太多的build-in library, 如果能想到自己的方法就好了。。。。
发表于 2004-6-11 15:37:09 | 显示全部楼层
Character ch = new Character('A');
ch.hashCode()>127?false:true;
 楼主| 发表于 2004-6-11 15:40:56 | 显示全部楼层
最初由 AirFish 发表
Character ch = new Character('A');
ch.hashCode()>127?false:true;


强。。我去试试!谢谢了
发表于 2004-6-11 15:54:34 | 显示全部楼层

楼主的要求真奇怪,一定要二进制判断吗?

//转为二进制
String bin = Integer.toBinaryString(ch.hashCode());

与0000 0000 0111 1111进行逻辑运算
也可以这样:
bin = bin.substring(0,9);
Integer.parseInt(bin)==0?true:false;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表