//判断字符串中是否含有中文
public static boolean hasFullSize(String inStr)
{
if (inStr.getBytes().length != inStr.length())
{
return true;
}
return false;
}
判斷字符串中是否含有中文字符
一般是利用ASC碼來判斷字符是中文還是英文,如果是中文,ASC碼小于0,而英文則是大于0。依據這個思路,相應的VB code如下:
Private Function HasChineseInString()Function HasChineseInString(textstring As String) As Boolean
Dim i As Integer
For i = 1 To Len(textstring)
If Asc(Mid(textstring, i, 1)) < 0 Then
' if chiness
HasChineseInString= True
Exit function
End If
Next
HasChineseInString=False
End Function
判断java字符串中是否含有中文字符2009-06-09 10:43判断java中是否含有中文字符
/**
* @version Created on 2009-6-09, 9:45:56
* @author zsh
* 判断是否今有中文字符
* @param value
* @return boolean
*/
public static boolean isIncludeChanse(String value)
{
String anotherString = null;
try {
anotherString = new String(value.getBytes("GBK"), "ISO8859_1");
}
catch (java.io.UnsupportedEncodingException ex) {
}
//System.out.println(aString.length() + "," + anotherString.length());
return value.length()!=anotherString.length(); //两个长度值不相等是说明是今有中文字符
}
方法 二
public static boolean IsChinese(char c)
{
return (int)c >= 0x4E00 && (int)c <= 0x9FA5;
}
方法 三 正则表达式
Java代码
String s="大牛这孩";
Pattern pattern=Pattern.compile("[\u4e00-\u9fa5]");
Matcher matcher=pattern.matcher(s);
System.out.println(matcher.matches());
---------------------------------------------------------------------
判断字符串是否是中文 收藏
方法一:
原文:http://www.soave.cn/blog/article.asp?id=232
在unicode 字符串中,中文的范围是在4E00..9FFF:CJK Unified Ideographs。
通过对字符的unicode编码进行判断来确定字符是否为中文。
protected bool IsChineseLetter(string input,int index)
{
int code = 0;
int chfrom = Convert.ToInt32("4e00", 16); //范围(0x4e00~0x9fff)转换成int(chfrom~chend)
int chend = Convert.ToInt32("9fff", 16);
if (input != "")
{
code = Char.ConvertToUtf32(input, index); //获得字符串input中指定索引index处字符unicode编码
if (code >= chfrom && code <= chend)
{
return true; //当code在中文范围内返回true
}
else
{
return false ; //当code不在中文范围内返回false
}
}
return false;
}
方法二:
public bool IsChina(string CString)
{
bool BoolValue = false;
for (int i = 0; i < CString.Length; i++)
{
if (Convert.ToInt32(Convert.ToChar(CString.Substring(i, 1))) < Convert.ToInt32(Convert.ToChar(128)))
{
BoolValue = false;
}
else
{
return BoolValue = true;
}
}
return BoolValue;
}
方法三:
**/**///// <summary>
/// 判断句子中是否含有中文
/// </summary>
/// <param >字符串</param>
public bool WordsIScn(string words)
{
string TmmP;
for (int i = 0; i < words.Length; i++)
{
TmmP = words.Substring(i, 1);
byte[] sarr = System.Text.Encoding.GetEncoding("gb2312").GetBytes(TmmP);
if (sarr.Length == 2)
{
return true;
}
}
return false;
}
方法四:
for (int i=0; i<s.length; i++)
{
Regex rx = new Regex("^[\u4e00-\u9fa5]$");
if (rx.IsMatch(s[i]))
// 是
else
// 否
}
正解!
\u4e00-\u9fa5 汉字的范围。
^[\u4e00-\u9fa5]$ 汉字的范围的正则
方法五:
unicodeencoding unicodeencoding = new unicodeencoding();
byte [] unicodebytearray = unicodeencoding.getbytes( inputstring );
for( int i = 0; i < unicodebytearray.length; i++ )
{
i++;
//如果是中文字符那么高位不为0
if ( unicodebytearray[i] != 0 )
{
}
……
方法六:
/**//**//**//// <summary>
/// 给定一个字符串,判断其是否只包含有汉字
/// </summary>
/// <param name="testStr"></param>
/// <returns></returns>
public bool IsOnlyContainsChinese(string testStr)
{
char[] words = testStr.ToCharArray();
foreach (char word in words)
{
if ( IsGBCode(word.ToString()) || IsGBKCode(word.ToString()) ) // it is a GB2312 or GBK chinese word
{
continue;
}
else
{
return false;
}
}
return true;
}
/**//**//**//// <summary>
/// 判断一个word是否为GB2312编码的汉字
/// </summary>
/// <param name="word"></param>
/// <returns></returns>
private bool IsGBCode(string word)
{
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(word);
if (bytes.Length <= 1) // if there is only one byte, it is ASCII code or other code
{
return false;
}
else
{
byte byte1 = bytes[0];
byte byte2 = bytes[1];
if (byte1 >= 176 && byte1 <= 247 && byte2 >= 160 && byte2 <= 254) //判断是否是GB2312
{
return true;
}
else
{
return false;
}
}
}
/**//**//**//// <summary>
/// 判断一个word是否为GBK编码的汉字
/// </summary>
/// <param name="word"></param>
/// <returns></returns>
private bool IsGBKCode(string word)
{
byte[] bytes = Encoding.GetEncoding("GBK").GetBytes(word.ToString());
if (bytes.Length <= 1) // if there is only one byte, it is ASCII code
{
return false;
}
else
{
byte byte1 = bytes[0];
byte byte2 = bytes[1];
if ( byte1 >= 129 && byte1 <= 254 && byte2 >= 64 && byte2 <= 254) //判断是否是GBK编码
{
return true;
}
else
{
return false;
}
}
}
/**//**//**//// <summary>
/// 判断一个word是否为Big5编码的汉字
/// </summary>
/// <param name="word"></param>
/// <returns></returns>
private bool IsBig5Code(string word)
{
byte[] bytes = Encoding.GetEncoding("Big5").GetBytes(word.ToString());
if (bytes.Length <= 1) // if there is only one byte, it is ASCII code
{
return false;
}
else
{
byte byte1 = bytes[0];
byte byte2 = bytes[1];
if ( (byte1 >= 129 && byte1 <= 254) && ((byte2 >= 64 && byte2 <= 126) || (byte2 >= 161 && byte2 <= 254)) ) //判断是否是Big5编码
{
return true;
}
else
{
return false;
}
}
}
分享到:
相关推荐
对于给定任意的字符串,如何快速的判断该字符串中是否包含汉字。
使用正则表达式判断字符串中是否包含中文汉字或者中文符号
PB判断字符串是否有中文
oracle中如何判断一个字符串是否含有汉字.pdforacle中如何判断一个字符串是否含有汉字.pdforacle中如何判断一个字符串是否含有汉字.pdf
快速判断字符串包含中文,通过字符串长度比较,高效率判断是否含有中文字符。
mfc 字符串中查找特殊字符 利用特殊字符分割字符串 mfc 字符串中查找特殊字符 利用特殊字符分割字符串 mfc 字符串中查找特殊字符 利用特殊字符分割字符串 mfc 字符串中查找特殊字符 利用特殊字符分割字符串 mfc 字符...
对网上问的一些问题的总结,封装成了一个工具类。完成的功能有: 1、判断字符串中是否有中文; 2、得到字符串中有几个中文; 3、判断字符串中有没有连续的几个中文;
Delphi 判断字符串中是否有中文,这个挺有意思,也很实用的技巧,在一串字符中判断是否有中文文字,根据所点字节都可以判断,不过本源码中所使用的方法也很有参考性,最终的运行示例效果如截图所示。
判断字符串有多少个汉字和标点符号, // GENERAL_PUNCTUATION 判断中文的“号 // CJK_SYMBOLS_AND_PUNCTUATION 判断中文的。号 // HALFWIDTH_AND_FULLWIDTH_FORMS 判断中文的,号
主要介绍了C#实现判断字符串中是否包含中文的方法,非常实用的功能,需要的朋友可以参考下
用php的strpos() 函数判断字符串中是否包含某字符串的方法 判断某字符串中是否包含某字符串的方法 if(strpos('www.idc-gz.com','idc-gz') !== false){ echo '包含'; }else{ echo '不包含'; } PHP strpos() ...
model中compile值可以根据需要更改,满足不同的检测需求 #判断一段文本中是否包含简体中文 import re zhmodel = re.compile(u'[\u4e00-\u9fa5]') #检查中文 ...以上这篇python 判断字符串中是否含
之前一个朋友问我,如何判断字符串中是否包含中文,其实解决的方法很简单,但觉着有必要写出给不知道的朋友们以参考,所以下面这篇文章主要介绍了利用Java正则表达式判断字符串中是否包含中文的方法,需要的朋友可以...
主要介绍了Android判断字符串中是否含字母、中文或数字的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
主要介绍了Go 验证字符串中是否包含中文,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
labview判断 英文还是汉字
用户输入一个字符串后,判断该字符串中包含几个汉字
易语言判断文本中是否有中文源码。@易语言资源论坛。
突然想到Oracle有一个编码转换的函数叫Convert,如果一个字符串编码转换前后不一样表示字符串里面含有非ASCII字符,这样得到结果。后写出来测试了一下,确实可行,5500万记录10秒钟扫描结束。以下是测试用例: ...