My.ADVISOR.com Sign-In
Username
Password
Sign Up 
Go to Article
Advanced Search 

ADVISOR TIPS

Remove FileMaker Pro Return Characters

Learn a new twist on a technique for removing leading and trailing carriage returns from a text field.

By John Mark Osborne, Database Pros president and owner, and FileMaker Advisor technical editor

UNLOCKED -- This article is provided to subscribers of FILEMAKER ADVISOR or DATABASED ADVISOR or FILEMAKER ADVISOR. To subscribe or renew, go to Advisor Store.

Kieren MacMillan recently showed me his nifty technique for removing leading and trailing carriage returns from a text field. This is a common technique for correcting data-entry errors or constructing return-separated lists. In the past, I used a simple approach:

LeftWords(MYTABLE::myfield; 999999999)

If you place this formula in an auto-enter calculation with the option to "do not replace existing value of field (if any)", it removes all carriage returns before and after text but leaves the returns between characters of text. For example, say you have the following text (invisible carriage returns have been displayed with the "¶" character):



John¶
Mark¶
Osborne¶


When this text runs through the auto-enter calculation, it comes out looking like:

John¶
Mark¶
Osborne

After you understand how the LeftWords, RightWords, and MiddleWords functions operate, you'll understand how the leading and trailing returns are removed. The word functions extract words from a text string by identifying word separators. If a word separator isn't surrounded by letters or numbers, the function removes it completely.

This technique works great as long as the text doesn't begin or end with a word separator you want to keep, such as a period, space, comma, or the many other characters that act as word separators. For example, if you run the following text through a word function, it removes the period at the end:



John¶
Mark¶
Osborne.¶


A more complicated formula removes leading and trailing returns but leaves other word separators. Read the comments for clarification of each part of the formula.

Let(
[@text = mytextfield; // Declare the field so it is easier to modify the formula when attaching to another field.
@stripped = Substitute(@text; "¶"; ""); // Remove all returns from the text string.
@firstChar = Left(@stripped; 1); // Grab the first character in the stripped text.
@lastChar = Right(@stripped; 1); // Grab the last character in the stripped text.
@firstpos = Position(@text; @firstChar; 0; 1); // Locate the position of the first character in the original text.
@lastpos = Position(@text; @lastChar; 0; PatternCount(@text; @lastChar))]; // Locate the position of the last character in the original text.

Middle(@text; @firstpos; @lastpos - @firstpos + 1) // Extract the text between the first and last characters.

)

In fact, you can use this technique to remove any leading or trailing characters by modifying the @stripped variable Substitute function to locate whatever characters you want.

Remove Return Characters

No reader comments ... yet.

    What do YOU think about this topic? Share your advice and thoughts using this form.

    Your Name

    REQUIRED : PUBLIC

    Your E-Mail

    REQUIRED : PRIVATE

    Job, Company

    OPTIONAL : PUBLIC

    City, State, Country

    OPTIONAL : PUBLIC

    Your Web Site

    OPTIONAL : PUBLIC

    Your Comment

    Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


    Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

    John OsborneTechnical editor John Mark Osborne is president and owner of Database Pros, offering FileMaker resources on the Internet. He is author of Scriptology, a speaker at FileMaker Developer Conferences and Macworld conferences, and a trainer for the Professional Training series created by FileMaker, Inc. http://www.databasepros.com jmo@filemakerpros.com

    Printer-friendly
    page layout

    Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro

    ADVISORAMA
    It's a good thing there's gravity or else when birds die, they'd stay where they were.
    -- Steven Wright

    ARTICLE INFO

    FileMaker Advisor

    Web Edition: 2008 Week 02, Doc #19365

    Print Edition: February/March 2008, Page 37

    SUBSCRIBER ONLY ARTICLE LOCKED

    Subscribe to FileMaker Advisor Magazine

    Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.

    FileMaker.Advisor.com

    Subscribe to Advisor Basics of FileMaker Pro

    Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!

    FileMaker.AdvisorBasics.com

    Secrets Of The Top Experts -- Now!

    See exactly how to do it, step-by-step, in Advisor Academy CDs created by the top experts. Click to see what you can learn right now.

    AdvisorAcademy.com

    Free E-Newsletters

    Keep up! Hot News, How-To, Tips & Tricks, Expert Advice, and more. Click to request your's free.

    AdvisorUpdate.info

    Need Know-How Now?

    What direction are you going with your business? Advisor Guides are packed with the answers you need to work smarter. Can you afford to fall behind?

    AdvisorStore.com

    Showcase Your Smarts

    Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!

    AdvisorTips.com

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2008 Advisor Media, Inc. All Rights Reserved.
    Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
    ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, Inc. in the United States and/or other countries.
    Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
    osboj037-03 posted 01/14/2008 modified 05/12/2008 03:44:10 AM ztfmfd/ztfmfd
    domino-144.advisor.com my.advisor.com 05/16/2008 12:14:45 PM