5 Replies Latest reply on Jun 26, 2013 7:32 AM by philmodjunk

# HELP: Calculation to reformat text

### Title

HELP: Calculation to reformat text

### Post

Hi Folks,

Does anyone have a good way of taking the following text in a field:

S11_12_13_11_11_14_11_12_13_11

And in a CALCULATION field automatically format it into the following:

S11_12_13_11_11_14_11_12_13_11

S11_12_13_11_11_14_11_12_13

S11_12_13_11_11_14_11_12

S11_12_13_11_11_14_11

S11_12_13_11_11_14

S11_12_13_11_11

S11_12_13_11

S11_12_13

S11_12

S11

So, basically, repeat the string minus the last section until you get to the end.

This is a short example. I have many strings that may be 50 or 100 ‘underscores’ long.

Any help would be appreciated.

Thanks..

TT

• ###### 1. Re: HELP: Calculation to reformat text

The problem is that the length of your patter is not fixed. If it were fixed a calculation could be easily created, but to handle the variable length of up to 100 elements, you'd need a recursive custom function to "loop" through the items of your list. That, in turn, requires Filemaker Advanced in order to define and install such a function in a Filemaker file.

Do you have filemaker advanced?

• ###### 2. Re: HELP: Calculation to reformat text

I do have FM Advanced version 12. You describe exactly the problem I want to address. I have not yet found a custom function that'll do the job and am not sure of how to write my own. Any help?

• ###### 3. Re: HELP: Calculation to reformat text

I am assuming that the results should appear as a list of values separated by returns.

//ListParse ( TheList )
//
//Use underscore as list separator and return list of values with one less list element in each subsequent value.
//
Let ( us = Position ( TheList ; "_" ; Length ( TheList )  ; -1 ) ; // Search right to left. 0 is returned if there are no underscores in TheList
Case ( not us ; TheList ;                                                                        // If no underscore, return entire parameter
List ( TheList ; ListParse ( Left ( TheList ; us - 1 ) ) )  // Use recursion to return list of values
) // Case
) // Let

If you passed the underscore character as a parameter to this function and modified the position function call to use it, you could parse lists with any number of different delimitting characters.

• ###### 4. Re: HELP: Calculation to reformat text

Hey Phil,

I just tried this out this morning and it works perfectly -- but I guess you already knew that!!

I had tried a few different ideas but could not get it to drop the underscore for each subsequent value.

I like your last idea of passing parameters to the function. Could be useful for me down the road. I work in an engineering test lab and have to filter through a lot of repetitive information.

Thanks a million.

TT

• ###### 5. Re: HELP: Calculation to reformat text

but I guess you already knew that

Yes, I like most such requests, I created and tested it--using the example data you provided, in my Known Bugs List database and then left it there for interested parties to discover...