没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
C#判断字符编码的方法总结判断字符编码的方法总结(六种方法六种方法)
主要介绍了C#判断字符编码的方法,结合实例形式总结分析了六种C#判断字符编码的技巧,具有一定参考借鉴价
值,需要的朋友可以参考下
本文实例总结了C#判断字符编码的方法。分享给大家供大家参考,具体如下:
方法一方法一
在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>
/// 判断句子中是否含有中文 宁夏大学 张冬 zd4004.blog.163.com
/// </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;
}
方法四:方法四:
资源评论
weixin_38683488
- 粉丝: 4
- 资源: 957
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功