Tayx / SSE (slut...@ccnet.com) wrote:
: Andrew Lee (will...@yorku.ca) wrote:
: : Does anybody have any FAST code for word wrapping arrays of strings?
: : I'm looking for something that will do the following:
: : stringY1 = 'Hey! This line is too long!';
: : then becomes
: : stringY1 = 'Hey! This line is too';
: : stringY2 = 'long!';
: : Thanks.
: : --
: : Andrew Lee
: : will...@yorku.ca
: This shouldn't be too hard and I don't see how it could be too slow.
: Something like this should work: (note that this is off the top of my
: head at 2:40 AM so just go for the general idea and not the exact code)
: const maxlength = 22;
: {other stuff}
: procedure checklength(s1 : string);
: var temp,s2 : string;
: begin
: if(length(s1)>maxlength) then
: begin
: move(s1Ymaxlength,temp,length(s1)-maxlength);
: {i've never actually used move for strings before so you may just want
: to use a loop to get the chars put in temp in case it doesn't work}
: delete(s1,maxlength,length(s1)-maxlength);
: s2 := temp; {s2 is the new second string with the last part of s1}
: end;
: end;
: hope that helps...
But you DID NOT implement word wrapping!
procedure Wrap(var S1,S2 : String; L : Byte; var OK : Boolean);
begin
if Length(S1)<=L then
OK:=TRUE
else
begin
while (L>1) and (S1YL<>' ') do
Dec(L);
if L>0 then
begin
S2:=S1;
S1Y0:=Chr(L);
Delete(S2,1,L);
OK:=TRUE;
end
else
OK:=FALSE;
end;
end;