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;
查看全文
相关阅读:
python_tkinter弹出对话框2
python_tkinter弹出对话框1
python生成图片二维码(利用pillow)
nginx配置ssl证书流程及常见问题
Django app安装,配置mysql,时区,模板,静态文件,媒体,admin
使用Git Flow规范!
python快速生成验证码
json&pickle模块
sys模块
常用模块
原文地址:https://www.cnblogs.com/sonicit/p/772409.html
最新文章
移远模组-BC95-工作模式之间关系
一般情况下的NB-IoT网络架构
【Offer】[37] 【序列化二叉树】
【Offer】[36] 【二叉搜索树与双向链表】
【Offer】[35] 【复杂链表的复制】
【Offer】[34] 【二叉树中和为某一值的路径】
【Offer】[33] 【二叉搜索树的后序遍历序列】
【Offer】[32] 【从上到下打印二叉树】
【Offer】[31] 【栈的压入、弹出序列】
【Spring】对持久层技术的整合
热门文章
【Spring】事务
【DataBase】事务
linux实操_rpm包和yum包
linux实操_进程管理
linux实操_网络配置
linux实操_硬盘
python_模块2
linux实操_定时任务调度
linux实操_权限管理
python_tkinter事件
Copyright © 2011-2022 走看看