看看这样行不//判断字符串中是否含有中文
public static boolean hasFullSize(String inStr)
{
if (inStr.getBytes().length != inStr.length())
{
return true;
}
return false;
}
public static boolean hasFullSize(String inStr)
{
if (inStr.getBytes().length != inStr.length())
{
return true;
}
return false;
}
function isStringAlt(obj,message) {
if( isString(obj) ){
return true;
}
displayMessage(M01005,message);
obj.focus();
return false;
}
----------------------------------------------------
//检测字符串,为数字与字母组合
function isString(obj){
var str=trim(obj.value);
var regexp=/^(\w+)$/;
return regexp.test(str);
}
-------------------------------------------------------
* 判断一个字符串中是否是汉字
* 计算字符串长度. 一个汉字的长度按2计算. 如果给定的字符串为null, 返回0.
*
* @param str
* 待计算长度的字符串
* @return 字符串长度
*/
public static int strlen(String str) {
if (str == null || str.length() <= 0) {
return 0;
}int len = 0;char c;
for (int i = str.length() - 1; i >= 0; i--) {
c = str.charAt(i);
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')) {
//字母, 数字
len++;
} else {
if (Character.isLetter(c)) { //中文
len += 2;
} else { //符号或控制字符
len++;
}
}
}return len;
}
String s = " abcd 程 ";
Pattern pa = Pattern.compile("[\u4E00-\u9FA0]",Pattern.CANON_EQ);
Matcher m = pa.matcher(s);
if(m.find())
{
System.out.println("表示有");
}
else
{
System.out.println("没有");
}
public class TestToDel {
public static void main(String[] args) {
String s = " :</td><td> <font color=red>陕西 西安</font> ";
Pattern pa = Pattern.compile("[\u4E00-\u9FA0]*",Pattern.CANON_EQ);
Matcher m = pa.matcher(s);
while(m.find()){
System.out.print(m.group());
}
}
}
偶是在J2SE下试的是可以的呀,能说说你是怎么用的吗?谢谢
public static boolean isCn(String value)
{
if(value == null)return false;
if(value.equals(""))return false;
char[] cs = value.toCharArray();
for(int i=0;i<cs.length;i++)
{
if(Character.getType(cs[i])!=5)return false;
}
return true;
}