在Delphi中的中英文混合的字符串中,怎样判断某个字符串变量中是否有汉字?
解决方案 »
- delphi皮肤控件问题:
- 关于使用菜单设计器中设置热键的小问题。。
- Delphi 如何才能在线程中动态创建窗体,并显示出来???
- ★★★我从TDBGridEh扩展的一个组件,半路出了点问题,进来帮我看看!★★★
- 关于 实体-关系图(Entity-Relationship Diagram)
- 如何知道我的MODEM是否支持来点显示?
- 急救!在delphi中如何使用MDX查询
- 如何建立带参数的form1, 如:form1:=Tform1.create(参数1,参数2)?
- 大家来谈谈对于两层结构改造成三层的想法
- delphi10使用idsmtp与idmessage连接QQ邮箱进行邮件发送问题
- 【中级擂台】24点算法!不能用C只能用Delphi!
- delphi 5.0在windows xp下如何调试????
while j<= strlen(pchar(字串)) do
if ord(字串[j])>128 then
showmessage('是汉字');
while j<= strlen(pchar(字串)) do
begin
if ord(字串[j])>128 then
begin
showmessage('是汉字');
inc(j,2);
end
else
inc(j,1);
end;
你这样写好了
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if ord(key)<128 then
key:=#0;
end;var
source: String;
chinese: String;
English: String;
len: Integer;
i: integer;
begin
source := '日本pig';
english := '';
chinese := '';
len := Length(source);
for i := 1 to len do
begin
if Ord(source[i]) > 128 then
chinese := chinese + source[i]
else
english := english + source[i];
end;
ShowMessage(chinese);
ShowMessage(english);
end;
showmessage('this string has Chinese character');
如果开始定义str的时候是string类型的,那么默认AnsiString 类型,这样的话,强制转换WideString(str)就对长度没影响,不会合并的,但是如果定义str的时候是定义WideString类型的,那么就会发生长度的变化~~~
偶是新人,^_^~~~~~
For single-byte (AnsiString) and multibyte strings, Length returns the number of bytes used by the string. For Unicode (WideString) strings, Length returns the number of bytes divided by two.对于AnsiString字符串,length返回的是字符串的字节数,而对于Unicode的字符串,则返回的是字节数的一般,所以length(widestring(str))就返回了str的实际字数