cancel
Showing results for 
Search instead for 
Did you mean: 

How to prevent text wrapping from breaking on words

Former Member
0 Kudos

I've got a formula in a Group Footer that concatenates the Group Header results. When I display it, however, the text wrapping cuts off words at the width of the text box. I've checked Can Grow, but can't really widen the text box due to the constraints of the layout. Here's my example:

GH2     Jenny

GH2     Jonny

GH2     Penny

GH2     Sally

GH2     Michael

GF2     Jenny, Jonny, Pe

            nny, Sally, Micha

            el

Is there any way to control the text wrapping so that it only breaks on a word? Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

abhilash_kumar
Active Contributor
0 Kudos

Hi Ahren,

Here's what you need to do:

1) Create another text object of the same width and count the maximum number of letters that can fit

2) It is advisable that you use a fixed width font like Courier New. If you can't however, you could count by using a letter that takes the most space - example W, X or Z.

3) You would then fill up the text object with either of these characters and this will help you count the letters that can fit in that space

4) Create a formula with this code:


stringvar s := {string_field_or_formula_variable};

local stringvar array arr := split(s," "); 

local numbervar i; 

numbervar lcount; 

lcount := 1; 

local numbervar fixed := 13;  //Replace this number with the letters you counted that can fit in the text object

local booleanvar nl := false; 

for i := 1 to ubound(arr) do 

    If i = 1 then 

    ( 

        local stringvar nstring := nstring + trim(arr[i]) + " "; 

        local numbervar rem := fixed - len(nstring); 

    ) 

    else if i <> 1 and i <> ubound(arr) then 

    ( 

         

        if len(arr[i]) <= rem then 

        ( 

            nstring := nstring + trim(arr[i]) + " "; 

            rem := (fixed*lcount) - (len(nstring)+lcount);        

            stringvar s := nstring; 

            numbervar t := rem;  

        ) 

        else 

        ( 

            nstring := rtrim(nstring) + chr(13) + trim(arr[i]) + " "; 

            lcount := lcount + 1; 

            nl := true; 

            rem := (fixed)- len(arr[i] + " "); 

        )         

    ) 

    else if i = ubound(arr) then 

    ( 

        if len(arr[i]) <= rem then 

        ( 

            nstring := nstring + trim(arr[i]); 

            rem := fixed - len(nstring); 

        ) 

        else 

        ( 

            nstring := nstring + chr(13) + trim(arr[i]); 

            rem := fixed - len(arr[i] + " "); 

        ) 

    ) 

); 

nstring; 

Note: Line #6 is where you would type in the number of letters that can fit

5) Make sure 'Can Grow' is enabled

Hope this helps.

-Abhilash

Former Member
0 Kudos

Hi Abhilash,

Thanks again for the response. The formula that was cutting the text was {MyFormula} in GF2. I made a new formula with your text above, replacing line 1 with:

stringvar s :+ {MyFormula}

In line 6, I made the number of characters to count 18. I put the formula in GF2, next to the original {MyFormula}. When I preview, they look identical. I went back into the formula and changed the character count on line 6 to many different variations (I tried 10, 13, 20, and 28), and it always looks identical to the original {MyFormula}. What am I missing?

Thanks!

abhilash_kumar
Active Contributor
0 Kudos

Do you have an example string from that formula?

I'll try to plug that string in the above formula and see how it breaks on my machine when it's set to 18 characters.

-Abhilash

Former Member
0 Kudos

Your solution worked perfectly! I figured out what I was doing wrong. In the original concatenating formula, I had joined the fields with a comma but no space after the comma.

My formula had looked like:

Join(brr,',');

It should have been:

Join(brr,', ');

I fixed that and it works great. Thanks again!

Answers (0)