procedure TForm1.Button1Click(Sender: TObject); var str: string; i: integer; temp : string; begin str := 'i love you 中国'; temp := ''; i := 0; while i < length(str) do begin while IsDBCSLeadByte(byte(str[i])) do begin temp := temp + widestring(str[i]+str[i+1]); i := i+2; end; inc(i); end; showmessage(temp); end;
Procedure TForm1.Create(Sender : TObject); var S_String : String; begin S_String := 'ddd中文ddsd'; Self.Caption := Copy(S_String,4,4); end;
procedure TForm1.Button12Click(Sender: TObject); var s:string; i,e,c:integer; begin s:=memo1.text; e:=0;c:=0; for i:=1 to length(s) do begin if (ord(s[i])>=33)and(ord(s[i])<=126) then begin inc(e); label1.caption:='英文个数:'+inttostr(e); end else if (ord(s[i])>=127) then begininc(c); copy(s,i,length(s)); showmessage(copy(s,i,length(s))); label2.caption:='中文个数:'+inttostr(c div 2); end; end;end;
function GetChinese(const ss:string):string; var i,len,st:integer; begin result:=''; i:=1; len:=length(ss); while (i<=len) and (not IsDBCSLeadByte(ord(ss[i]))) do inc(i); if i<=len then begin st:=i; while (i<=len) and (ord(ss[i]) and $80=$80) do inc(i); result:=copy(ss,st,i-st); end; end;
coreblood(菜码) 的代码可以的,不管有没有空格,你可以测试一下。
感谢zzllabc(龙)!也感谢coreblood(菜码)! 结账!!
function TForm1.DistillCN(const Value: string): string; var i:integer; begin i:=1; while i< length(Value) do //最后一个字符不需要检查 begin if ord(Value[i])>$80 then begin Result:=Result+Value[i]+Value[i+1]; inc(i,2); end else inc(i); end; end;
65
?asc("在在职")
-11046
?Asc("AAAA")
65
?Asc("在")
-11046
?Asc("“")
-24144
var
str: string;
i: integer;
temp : string;
begin
str := 'i love you 中国';
temp := '';
i := 0;
while i < length(str) do
begin
while IsDBCSLeadByte(byte(str[i])) do
begin
temp := temp + widestring(str[i]+str[i+1]);
i := i+2;
end;
inc(i);
end;
showmessage(temp);
end;
var
S_String : String;
begin
S_String := 'ddd中文ddsd';
Self.Caption := Copy(S_String,4,4);
end;
var s:string;
i,e,c:integer;
begin
s:=memo1.text;
e:=0;c:=0;
for i:=1 to length(s) do
begin
if (ord(s[i])>=33)and(ord(s[i])<=126) then
begin
inc(e);
label1.caption:='英文个数:'+inttostr(e);
end
else
if (ord(s[i])>=127) then
begininc(c);
copy(s,i,length(s));
showmessage(copy(s,i,length(s)));
label2.caption:='中文个数:'+inttostr(c div 2);
end;
end;end;
。
IORILI(眼镜@_@) :我不是要个数,我是要把中文提出来
var i,len,st:integer;
begin
result:='';
i:=1;
len:=length(ss);
while (i<=len) and (not IsDBCSLeadByte(ord(ss[i]))) do
inc(i);
if i<=len then
begin
st:=i;
while (i<=len) and (ord(ss[i]) and $80=$80) do
inc(i);
result:=copy(ss,st,i-st);
end;
end;
结账!!
var
i:integer;
begin
i:=1;
while i< length(Value) do //最后一个字符不需要检查
begin
if ord(Value[i])>$80 then
begin
Result:=Result+Value[i]+Value[i+1];
inc(i,2);
end
else
inc(i);
end;
end;