Delphi相談室その3
■ このスレッドは過去ログ倉庫に格納されています
0683デフォルトの名無しさん
NGNGものすごく大きい文字列を変換する場合はメモリーが勿体ないから
最初に少し余裕取って、CRLF毎に余裕残を減らすとかすればいいけど
今時のパソコンならこれで十分だろう
function ChangeLineBreakes(const S: String; Style: TTextLineBreakStyleMultiPlatform): String;
const
CR =#$D; //#13
LF =#$A; //#10
crlf:array [TTextLineBreakStyleMultiPlatform] of String=(CR+LF,CR,LF);
var rp,wp,i:Integer;
repstr:string;
label putCRLF;
begin
repstr:=crlf[Style];
rp:=1;
wp:=1;
SetLength(Result,Length(S)*2);
for i:=1 to Length(S) do Result[i]:=#0;
while rp<=Length(S) do begin
case S[rp] of
CR: begin
if not (rp=Length(S)) then
if S[rp+1] =LF then inc(rp);
goto putCRLF;
end;
LF: begin
if not (rp=Length(S)) then
if S[rp+1] =CR then inc(rp);
putCRLF:
for i:=1 to Length(repstr) do Result[wp+i-1]:=repstr[i];
inc(wp,length(repstr));
end;
else begin Result[wp]:=S[rp];inc(wp);end;
end;
inc(rp);
end;
setLength(Result,wp-1);
end;
■ このスレッドは過去ログ倉庫に格納されています