为了避免汉字拆分出错,现把读入的行转化为widestring,然后拆分,
最后可根据需要,还原成ansistring,算法如下:as : AnsiString;
ws : WideString;
...
as := read a line;
ws := WideString( as );
process ws, can use wideString( #13#10 ) to devide the widestring-ws
into severak lines as ws1,ws2...
then change ws1,ws2,... to as1,as2,..
最后可根据需要,还原成ansistring,算法如下:as : AnsiString;
ws : WideString;
...
as := read a line;
ws := WideString( as );
process ws, can use wideString( #13#10 ) to devide the widestring-ws
into severak lines as ws1,ws2...
then change ws1,ws2,... to as1,as2,..
但有新的问题,英文与汉字都为一个宽字符,这样对于
40个WideString字符,若全是英文,则为40个
AnsiString字符,若全是汉字,则实为80个AnsiString
字符,若有英有中混合则实际字符数为一笔糊涂帐;
while ByteType(AString, i) = mbLeadByte then
Dec(i);S1 := Copy(AString, 1, i - 1);
AString := Copy(AString, i, Length(AString));
草书一番,大意如此,自己再算算看啦,呵呵
wis : WideString;
sub : Integer; //汉字的个数
Begin
ans := '盗版delphi';
wis := WideString( ans );
sub := Length( ans ) - Length( wis );
End;
例如,在AnsiString的79或80个字符后截断,到了WideString中怎么截呀;
就可知道能否在某处断开,如何不能,再往前去一个字符!!!!!!!!十分满意!
在这里WideString倒起不了作用,但也发鼓励分;