Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

WordWrap ( Text ; Size )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 3.9  (46 votes)
  Discuss this Custom Function

Jonathan Stark, Jonathan Stark Consulting
http://jonathanstark.com/

Wraps text to specified max line character count, without breaking words

Sample Input:
This is a really long text string that I need to display narrowly in a huge text field. Or some other weird reason like that.
Sample Output:
This is a
really long
text string
that I need
to display
narrowly in a
huge text
field. Or
some other
weird reason
like that.


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

Wraps text to specified max line character count, without breaking words. I used this function for compiling invoices as text for output as email, like so:

<pre>
Qty Description Price
=======================================
3 Here is the long $34.00
item description
that I needed to
wrap.
---------------------------------------
2 Next item $37.00
---------------------------------------
2 Next item $37.00
=======================================

</pre>

UPDATE:

Thank you to all the folks who emailed me about the "question mark" result (undefined result).

Yes, I am aware of the question mark. But, I feel that is appropriate for the function to return "undefined" because you are asking to do something impossible. IOW - the function can't wrap a line to 10 characters without breaking a word, if there is a word on that line that is 12 characters long.

HTH,
j

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 6 comments

Thanks - great function. Here is my slightly modified version, if you don't want to remove any existing carriage returns in your text, but just truncate the lines that are longer than your specified "size". I use this for things like the plain text version of emails which I want to add a hard word wrap at 60 characters, but retain all existing headings and carriage returns.

Let ([
TruncatedText = Left ( Text ; Size + 1 ) ;
CountOfSpaces = PatternCount ( TruncatedText ; " " ) ;
CountOfReturns = PatternCount ( TruncatedText ; "¶" ) ;
PositionOfLastSpace = If ( CountOfReturns > 0 ; Position ( TruncatedText ; "¶" ; 1 ; 1 ) ; Position ( TruncatedText ; " " ; 1 ; CountOfSpaces ) );
AddReturn = If ( CountOfReturns > 0 ; "" ; " ¶" );
ThisLine = Trim ( Left ( TruncatedText ; PositionOfLastSpace ) ) ;
UnprocessedText = Right ( Text ; Length ( Text ) - PositionOfLastSpace ) ;
Result = If ( Length ( Text ) ≤ Size ; Text; ThisLine & AddReturn & WordWrap ( UnprocessedText ; Size ) )
];
Result
)

Tanya, Sydney
April 13, 2011 4:57pm

Here is another revised version of this WordWrap function which I find good for word wrapping email text. This version will not throw an error if there happens to be a string in your text longer than the "size" specified as input to the function, eg- if there is a long string in your text such as a URL, it will retain it rather than wrapping it.

Let ([
RequestedSizeText = Left ( Text ; Size + 1 ) ;
FullLineText = Left ( Text ; Position ( Text ; "¶" ; 1 ; 1 ) ) ;

//if one line appears to be a long string (such as a url) allow the full line, otherwise set to requested length
TruncatedText = If ( PatternCount ( RequestedSizeText ; " " ) = 0 ; FullLineText ; RequestedSizeText ) ;

CountOfSpaces = PatternCount ( TruncatedText ; " " ) ;
CountOfReturns = PatternCount ( TruncatedText ; "¶" ) ;

PositionOfLastSpace = If ( CountOfReturns > 0 ; Position ( TruncatedText ; "¶" ; 1 ; 1 ) ; Position ( TruncatedText ; " " ; 1 ; CountOfSpaces ) );
AddReturn = If ( CountOfReturns > 0 ; "" ; " ¶" );
ThisLine = Trim ( Left ( TruncatedText ; PositionOfLastSpace ) ) ;
UnprocessedText = Right ( Text ; Length ( Text ) - PositionOfLastSpace ) ;

Result = If ( Length ( Text ) ≤ Size ; Text; ThisLine & AddReturn & WordWrap ( UnprocessedText ; Size ) )
];

Result
)

Tanya Sager, Sydney, Australia
June 28, 2011 9:04pm

@Tanya Sager:

Hello!
Unfortunately, your function does throw a "?" if called for example with:

Wordwrap ("1234567890123456789012345678901234567890"; 30)

Or am I missing something?
(tested with FMPA 11.0.4, Mac)

I am searching for a text wrap function which works always, it seems I have to code it on my own ... I will try ...

Patrick Horn, Saarbrücken, Germany
May 08, 2012 11:18am

I've just uploaded a function, icio_linewrap (Text; Size; origsize) which does not throw a ? whatever you give it (at least I haven't managed to yet!).
Hope this helps all those still struggling!

Chris Jones, Oxford, UK
June 20, 2012 1:58pm

what is or where can I find the wordwrap ( ) or am I just missing something? Thanks much.

SK8path, Tacoma, WA
September 02, 2012 10:30am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 8 + 8 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ProperAllWords ( text )
  (Thu, Dec 14, 5:19pm)
2. MatchExist ( SourceTable.Field ; DestTable.Field ; ReturnField )
  (Thu, Dec 14, 1:07pm)
3. BVR_Format ( bvr )
  (Wed, Dec 13, 5:32pm)
4. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
5. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
6. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
7. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
8. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)

RSS Feed of Custom Functions