Why not just let the user enter 0;3;2;1
Or do you need other text in there too?
You could also do %0%other text%3%again other text%2% - %1%
In that case you can just look for %index% and replace it with the string index.
There are two ways to tackle this:
1) Loop through all the strings in the TStringList and replace %index% with the string content on that index
2) Extract all %index% from the mask and check if index is only numbers/valid index and replace it with the corresponding string.
Efficiency would depend on how large the TStringList is. If you have thousands of entries in the list you want to go for option 2. If the TStringList is limited option 1 would be easiest to program.
Option 1 would be:
Masked := '%0%other text%3%again other text%2% - %1%';
for I := 0 to sl.Count - 1 do
Masked := StringReplace(Masked, '%' + I.ToString + '%', sl[I], [rfReplaceAll]);
Note: If you have %index% where index doesn't exist in the TStringList, it will not be replaced so you would end up with %index% in the end-result. If that is a problem go with option 2.
@Thaddy, how is that a dynamic solution for when the user enters something else in a different order in the masked-edit?
I have 1 Edit field where user is supposed to enter a mask for example:
...
I have a button and If user presses it then for example in Memo1 a line will be added like this