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;
查看全文
相关阅读:
Eclipse 重构功能的使用与重构快捷键
Idea工具常用技巧总结
Eclipse常用快捷键
RabbitMQ的原理和使用
总结消息队列RabbitMQ的基本用法
rabbitmq常见运维命令和问题总结
关于RabbitMQ关键性问题的总结
Rabbit MQ 面试题相关
RabbitMQ的使用总结
史玉柱: 我的成功不是偶然(底下还有一堆相关链接)
原文地址:https://www.cnblogs.com/sonicit/p/772409.html
最新文章
Java实现 LeetCode 153 寻找旋转排序数组中的最小值
Java实现 LeetCode 153 寻找旋转排序数组中的最小值
Java实现 LeetCode 153 寻找旋转排序数组中的最小值
Java实现 LeetCode 152 乘积最大子序列
Java实现 LeetCode 152 乘积最大子序列
Java实现 LeetCode 152 乘积最大子序列
Java实现 LeetCode 151 翻转字符串里的单词
Java实现 LeetCode 151 翻转字符串里的单词
Java实现 LeetCode 151 翻转字符串里的单词
Java实现 LeetCode 150 逆波兰表达式求值
热门文章
DirectShow建立一个视频捕捉程序
DirectShow系统初级指南
Load and Unload
Windbg的gflags.exe -- Attach调试利器
一个发送邮件的C++库–jwsmtp
DrawDib函数组的使用
一种简单实用的全屏方法
在VC资源文件中加入声音资源
VC++实现位图显示透明效果--实现原理
用VC制作应用程序启动画面
Copyright © 2011-2022 走看看