The FString format.

FString is a format created to extract data from complex data structures in order to create
well-formed files or strings.

The basic FString

- Any string is considered an FString.
- Any parts of the string starting with ‘{$’ and ending with ‘$}’ is a replacement directive.

The replacement directive

The replacement directive is any part of the string starting with ‘{$’ and ending with ‘$}’
The first part of this directive is the lookup key. This is a name referencing a value in the context
in which the FString is evaluated.

So if we were to evaluate the FString “Hello {$user_name$}” in the context

{
  "user_name":"Bob"
}

We would get the string “Hello Bob”

There are some reserved lookup keys to enable different more complex replacements.

Key Description
* or _ Treat the whole input as the result
0 1 2… Look up the numbered element in a list
name Look for the key name in the context

For each in collections

Some times the context contains lists of values.

{
  "users":[
    "Bob",
    "Ben",
    "Barbra"
}

The special character ‘|’ is used to repeat a string for each of the values in a list.

Key Description
| Repeat the folowing FString for each selected element
¤ Seperated by

So the expression {$users|{$_$}¤, $} is interpreted as look up the key “users”, treat the value as a list and for each element in the list evaluate “{$_$}” meaning insert the value. Seperate these values by “, “.
The expression would yeald the string “Bob, Ben, Barbra”.

examples

Expression What it does result
{$*|”{$_$}“¤, $} Treat the input as a list. For every element insert the value inside “” “Bob”, “Ben”, “Barbra”
Hi {$name$} Replace with the value named “name” Hi Bob
Hi {$1/name$} Treat the input as a list. Replace with the name of the second value. Hi Ben

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment