社区
C#
帖子详情
怎么识别是一中文汉字还是两个字符呢?
gggjjj
2006-11-01 08:42:17
一个中文汉字在C中占两个字节,一个西文字符占一个字节,那么怎么识别16位的一个串是代表一个中文字符呢还是两个西文字符呢?
...全文
232
5
打赏
收藏
怎么识别是一中文汉字还是两个字符呢?
一个中文汉字在C中占两个字节,一个西文字符占一个字节,那么怎么识别16位的一个串是代表一个中文字符呢还是两个西文字符呢?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
sanniko
2006-11-01
打赏
举报
回复
[DllImport("kernel32")]
private static extern int lstrlenA(string lpString);
zzPandazz
2006-11-01
打赏
举报
回复
现在英文也是两个了
jxhwei
2006-11-01
打赏
举报
回复
Unicode的特点是:
不管哪一国的字符码均以两个Byte表示,例如"A"在Unicode则是16进制41和00的组合,即4100,高位41(转换为Ascii码即是65=A)
如果用的是Ascii码,自然不存在这个问题,如果是Unicode码,那么,如果后2位是00的,就是英文字符
gggjjj
2006-11-01
打赏
举报
回复
最后一句有些看不懂啊。
Knight94
2006-11-01
打赏
举报
回复
通过Encoding来判断,例如:
private int GetChsCharLength( string strValue )
{
if( strValue == null || strValue == "" ) return 0;
Encoding encGB = Encoding.GetEncoding( "gb2312" );
Encoding encUnicode = Encoding.Unicode;
return strValue.Length - ( encUnicode.GetByteCount( strValue ) - encGB.GetByteCount( strValue ) );
}
private int GetAniCharLength( string strValue )
{
if( strValue == null || strValue == "" ) return 0;
Encoding encGB = Encoding.GetEncoding( "gb2312" );
Encoding encUnicode = Encoding.Unicode;
return encUnicode.GetByteCount( strValue ) - encGB.GetByteCount( strValue );
}
C# 编辑Office源码与文档
源码直接下载地址: https://pan.quark.cn/s/44d9e3fb0403 IDLE is Python's Tkinter-based Integrated DeveLopment Environment. IDLE emphasizes a lightweight, clean design with a simple user interface. Although it is suitable for beginners, even advanced users will find that IDLE has everything they really need to develop pure Python code. IDLE features a multi-window text editor with multiple undo, Python colorizing, and many other capabilities, e.g. smart indent, call tips, and autocompletion. The editor has comprehensive search functions, including searching through multiple files. Class browsers and path browsers provide fast access to code objects from a top level viewpoint without dealing with code folding. There is a Python Shell window which f...
AI Agent 科研全流程教学包,能教学生从零部署 Codex、Claude Code、OpenClaw、Hermes 等 A.zip
一个专为本科/研究生论文写作设计的AI技能,支持工科、心理学、教育学、管理学等多学科领域,提供符合中国学术规范(GB/T 7714-2015)的论文写作、数据分析、参考文献管理一体化解决方案。
com.techflow.assist_2.0.3.apk
com.techflow.assist_2.0.3.apk
<数据集>yolo玉米叶片病害
识别
<目标检测>
YOLO与VOC格式的玉米叶片病害
识别
数据集,适用于YOLO系列、Faster Rcnn、SSD等模型训练,类别:CommonRust、GrayLeafSpot、Healthy、Northe,图片数量4027。文件中包含图片、txt标签、指定类别信息的yaml文件、xml标签,已将图片和txt标签划分为训练集、验证集和测试集,可直接用于YOLOv5、YOLOv6、YOLOv7、YOLOv8、YOLOv9、YOLOv10、YOLOv11、YOLOv12、YOLOv13、YOLOv26等YOLO系列算法的训练。
【网安-Web渗透测试-靶场系列】AWD-Platform(ctf-hub)
【网安-Web渗透测试-靶场系列】AWD-Platform(ctf-hub)
C#
111,131
社区成员
642,542
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章