8 Replies Latest reply on May 24, 2016 11:42 AM by christo

# Sequentially number lines in a text field

Each line has a return character at the end. I have to put sequential numbers at the beginning of each line, either by calculation or script. There must be a previous solution, but I don't seem to be entering the correct words to find it.

Thank you

• ###### 1. Re: Sequentially number lines in a text field

Via script:

Set Variable [ \$text ; table::yourfield ]

Loop

Set Variable [ \$i ; \$i + 1 ]

Set Variable [ \$newtext ; List ( \$newtext ; \$i & " " & GetValue ( \$text ; \$i ) ) ]

Exit Loop If [ \$i = ValueCount(\$text) ]

End Loop

Set Field [ table::yourfield ; \$newtext ]

You could also write a recursive custom function that will do all of this in the calculation engine.

• ###### 2. Re: Sequentially number lines in a text field

If you have FMP advanced, you can make use of the custom function included in the attachment.

If you don't have it, you can use the script included as well.

2 of 2 people found this helpful
• ###### 3. Re: Sequentially number lines in a text field

Your answer is correct as well - thought I could click on both as correct. Thanks so much.

• ###### 6. Re: Sequentially number lines in a text field

Here's one more example of a custom function that seems to work. This one puts a period and a space after the number. (Thanks to Dale Miller)

Number_Lines (input, start)

If (not is empty (input);

start & ". " & GetValue (input; 1) & if (ValueCount (input) > 1;

¶ & Number_Lines (MiddleValues (input; 2; 99999) start + 1)); ""

)

• ###### 7. Re: Sequentially number lines in a text field

download again the solution I posted, it allows you to define freely the separator between the number and the line (it can be space + ")" + tab + ". " or whatever you want.

• ###### 8. Re: Sequentially number lines in a text field

Yes, I saw that. Just wanted to point out I'd done it in that last sample, which is no better than yours, just slightly different.

Sent from my iPod