Board index » delphi » Word Wrapping

Word Wrapping

Does anybody have any FAST code for word wrapping arrays of strings?
I'm looking for something that will do the following:

string[1] = 'Hey!  This line is too long!';

then becomes

string[1] = 'Hey!  This line is too';
string[2] = 'long!';

Thanks.
--
Andrew Lee
will...@yorku.ca

 

Re:Word Wrapping


Quote
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:

: string[1] = 'Hey!  This line is too long!';

: then becomes

: string[1] = 'Hey!  This line is too';
: string[2] = '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(s1[maxlength],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...

  TayX
slut...@ccnet.com

Re:Word Wrapping


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;

Re:Word Wrapping


In article <3shfci$...@sunburst.ccs.yorku.ca>, will...@yorku.ca (Andrew Lee) says:
Quote

>Does anybody have any FAST code for word wrapping arrays of strings?
>I'm looking for something that will do the following:

>string[1] = 'Hey!  This line is too long!';

>then becomes

>string[1] = 'Hey!  This line is too';
>string[2] = 'long!';

>Thanks.
>Andrew Lee

Hi Andrew,
actually, Turbo Power's libraries (opro & tpro) will do that, and a large
bunch of other things very nicely.  I know that you don't want to hear
"Buy this package" but I've found far too many things in there to not
recommend it.  Other than having a copy, I am not affiliated with
them in any way.
Hope this helps,
Jochen

________________________________________________________________________
joch...@berlin.snafu.de                        71270,3...@compuserve.com
joc...@cs.umd.edu                              enough already

Other Threads