Enhanced Parameters for Text Functions

Idea created by Chris Irvine on Aug 29, 2016
    Active
    Score15

    The Position() function is one text function that supports a negative index for occurrence. Add similar capabilities to all the other text processing functions, allowing indexes to be negative or parameters omitted when it conveys a sensible meaning.

     

    Any negative number in an index would simply read as "from the right" or "from the end". Omitting the length argument in a Middle function would assume you want string to the end.  I'd wager that I could remove close to 50% of my Length(), WordCount(), and ValueCount() function uses if these capabilities existed. In some cases the could result in faster code, and in many cases it could result in more readable and bug-free code.

     

    Here is an example of a laborious calc (found right in FileMaker's help documentation):

    Right(Name;Length(Name) - Position(Name;“ “;1;1)) returns Cannon, when the Name field contains Michelle Cannon.

     

    Today, someone might be tempted to approximate the above calculation using two functions instead of three:

    Middle(Name;Position(Name;“ “;1;1)+1;99999999)

     

    Even better, and more accurate, would simply be:

    Middle(Name;Position(Name;“ “;1;1)+1) // length omitted

     

    If you go on to allow negative position, you can periodically replace the Right function.

    Left("Pickle";$x) => Middle("Pickle";1;$x) // This already works

    Right("Pickle";$y) => Middle("Pickle";-$y)

     

    There is nothing wrong with the Left or Right functions, but a universal middle function could result in less switchboard code.

     

    In a similar vain, various 'word' and 'value' calculations could be enhanced:

    // second word from the end

    MiddleWords($my_text;WordCount($my_text)-2;1) => MiddleWords($my_text;-2;1)

     

    // second value from the end, w/<cr>

    MiddleValues($my_vals;ValueCount($my_vals)-2;1) => MiddleValues($my_vals;-2;1)

     

    // last value w/o <cr>

    GetValue($my_vals;ValueCount($my_vals)-1) => GetValue($my_vals;-1)

     

    P.S. This would go great with text processing optimizations discussed with other ideas such as High Performance Text - List of Values and ForEach[Values] new script step for major performance boost