zoukankan
html css js c++ java
Delphi中实现全角转半角
function SbctoDbc(s:
string
):
string
;
var
nlength,i:integer;
str,ctmp,c1,c2:
string
;
{
在windows中,中文和全角字符都占两个字节,
并且使用了ascii chart
2
(codes
128
-
255
)。
全角字符的第一个字节总是被置为163,
而第二个字节则是相同半角字符码加上128(不包括空格)。
如半角a为65,则全角a则是163(第一个字节)、
193
(第二个字节,
128
+
65
)。
而对于中文来讲,它的第一个字节被置为大于163,(
如
'
阿
'
为:
176
162
),我们可以在检测到中文时不进行转换。
}
begin
nlength:
=
length(s);
if
(nlength
=
0
) then
exit;
str:
=
''
;
setlength(ctmp,nlength
+
1
);
ctmp:
=
s;
i:
=
1
;
while
(i
<=
nlength)
do
begin
c1:
=
ctmp[i];
c2:
=
ctmp[i
+
1
];
if
(c1
=
#
163
) then
//
如果是全角字符
begin
str:
=
str
+
chr(ord(c2[
1
])
-
128
);
inc(i,
2
);
continue
;
end;
if
(c1
>
#
163
) then
//
如果是汉字
begin
str:
=
str
+
c1;
str:
=
str
+
c2;
inc(i,
2
);
continue
;
end;
if
(c1
=
#
161
) and (c2
=
#
161
) then
//
如果是全角空格
begin
str:
=
str
+
'
'
;
inc(i,
2
);
continue
;
end;
str:
=
str
+
c1;
inc(i);
end;
result:
=
str;
end;
查看全文
相关阅读:
如何把this指针转换成boost的shared_ptr
字符指针数组 和 字符指针的指针 即 char ** arr VS char * arr[]
latex图片自动浮动到最后一页单独占用一页
Android首次开发的经历
jvm内存问题诊断1
性能优化从删除子查询做起
资治通鉴故事止谤莫如自修
Forward框架的逆袭:解析Forward+渲染
FFT镜头效果解析
最先进的开源游戏引擎KlayGE 4.1发布
原文地址:https://www.cnblogs.com/sonicit/p/772409.html
最新文章
特殊符号输入器
如何重写控件
No. 9269 Windows 7样式Aero TreeView控件(四):代码公开
No. 9073 Sharepoint 2010 在FBA模式下的诡异现象
[翻译]No.9354 SharePoint Pages(3)之网站页面
No. 8958 实现Windows 7样式Aero TreeView控件(三):样式绘制
No. 8998 吐糟,你爱看不看
No.8948 实现Windows 7样式Aero TreeView控件(二):实现整行选中
[翻译]No.9352 SharePoint Pages(1)之SharePoint页面体系架构
No. 8948 实现Windows 7 样式 Aero TreeView 控件(一):差异分析
热门文章
No. 8982 你有多久没有~?
[翻译]No.9353 SharePoint Pages(2)之SharePoint母版页
发一篇关于 数组名称 和 指针区别 的专题探讨
doxygen在项目中的实践
使用 dlopen 报错 only ET_DYN and ET_EXEC can be loaded
remarks of 性能测试 (持续更新) 关于性能测试的思考
linux 中与标准库的strftime相对的有一个strptime的函数
如何把this指针转换成boost的shared_ptr
C语言中关于字符数组与字符指针的本质区别
makefile 速成
Copyright © 2011-2022 走看看