ShowMessage(copy(widestring(edit1.text),1,3));学习 up
如果要照顾到数据库字段的长度,那就有可能截断。 如果不截断,就可能超过字段长度。 一个方法是把最后的半个汉字丢弃: var s:string; i:Integer; Edit1.Text:='123我们'; s:=Copy(Edit1.Text,1,6); i:=1; while i<=Length(s) do begin if s[i]>#127 then i:=i+1; if i>Length(s) then begin s:=Copy(s,1,i-2); break; end; i:=i+1; end;
ShowMessage(copy(widestring(edit1.text),1,3));
up
如果不截断,就可能超过字段长度。
一个方法是把最后的半个汉字丢弃:
var
s:string;
i:Integer; Edit1.Text:='123我们';
s:=Copy(Edit1.Text,1,6);
i:=1;
while i<=Length(s) do
begin
if s[i]>#127 then
i:=i+1;
if i>Length(s) then
begin
s:=Copy(s,1,i-2);
break;
end;
i:=i+1;
end;