一个edit中输入一串字符,有汉字、数字和字母,想计算一下长度,一个汉字只算一个字符,一个数字也算一个字符,但是用length(edit.text)和strlen(pchar(edit.text))得到的长度都是把汉字作为2个来计算的。请教各位,有什么函数能满足我的要求?
另外,我还要将string按长度分割,汉字也只能按一个字符来算。
另外,我还要将string按长度分割,汉字也只能按一个字符来算。
调试欢乐多
procedure TForm1.Button1Click(Sender: TObject);
var
s : WideString;
begin
s := edit1.Text;
showmessage (inttostr(Length(s)));
end;
var
a:WideString;
begin
a:='例如123ABC';
showmessage(inttostr(length(a)));
showmessage(Copy(a,1,2));
end;
function CharCounts(Text : string): integer;
var
Len : integer;
j,i : integer;
begin
Result := 0;
Len := Length(Text);
j := 0;
for i := 1 to Len do
if ord(Text[i]) > 127 then Inc(j);
Len := Len - (j div 2);
Result := Len;
end;
adoquery1.open;
showmessage(adoquery1.fieldbyname('strlength').asstring);