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;
查看全文
相关阅读:
机器学习(Machine Learning)&深入学习(Deep Learning)资料
漫谈 机器学习
Android 屏幕滑动事件
Andriod中绘(画)图----Canvas的使用详解
android studio上代码编译调试中遇到的一些异常记录
Android签名详解(debug和release)
如何用AndroidStudio导入github项目
java synchronized详解
视频编解码学习之一:理论基础
Android 环境下编译FFmpeg
原文地址:https://www.cnblogs.com/sonicit/p/772409.html
最新文章
Image Filter
CVPR 2017 papers on the web
为什么凸优化这么重要?知乎解答
ceshi
sonar:sonarqube6.7.6与mysql5.7版本不匹配
通过命令行方式连接redis
jenkins:执行远程shell脚本时,脚本没有生效
sonar全攻略
jenkins:多个job时怎么按照一定顺序执行构建
Maven错误:was cached in the local repository, resolution will not be reattempted until the update
热门文章
jenkins迁移
jenkins:忘记登录密码怎么办
ThinkPHP 3.2.3 加减乘法验证码类
正态分布的前世今生(下)
正态分布的前世今生(上)
正则表达式30分钟入门教程
23种设计模式
android 三种定位方式
自然语言处理怎么最快入门?
几本自然语言处理入门书
Copyright © 2011-2022 走看看