【发布时间】:2013-02-11 11:03:10
【问题描述】:
我是 java 和编码的新手,因此这个问题。
我基本上有一个文本文件,其中包含以十六进制值表示的一组有效字符。 例子: 0x2000-0x4002,0x5002-0x5F00
现在我有了另一个包含字符串的文件。 例子: 我正在尝试使用这个文件。
我的问题是检查第二个文件的每个字符是否有效,是否在上述文件描述的范围内。
这就是我正在做的:
public class Test
{
//This is a function used to build the ranges.
public void build range() {}
//This function will test whether the string str is in given range.
public bool check range(String str)
{
int codePointCount = str.codePointCount(0, str.length());
for( in ti =0; i< codePointCount; i++)
{
int value = str.codePointAt(i);
if( value >= 2000 && value <= 4002 )
continue;
if( value >= 5002 && value <= 5F00 )
continue;
return false;
}
return true;
}
}
请告诉我这段代码是否正确,或者我在编码方面遗漏了什么。
【问题讨论】:
-
编译是否正确?我怀疑!
标签: java string unicode encoding utf-8