Yeah you can look at the string.Format method which is the one ultimately used by Grasshopper.
The curly brackets represent placeholders within the formatting string. So assuming you are formatting with two values (one a floating point value at index=0, the other an integer at index=1).
The expression for this will always look like this: Format(pattern, x, y)
If the pattern
is just a string without any curly brackets, it always yields the same result, regardless of the values of x
and y
. For example Format("X=x", x, y)
just gives you the text “X=x”.
For the actual value of x
to be inserted into the result, you need to write Format("X={0}", x, y)
. Of course now y
is still ignored because it isn’t referenced in the pattern. To use both values, you’d write something like Format("X={0}, Y={1}", x, y)
.
You are of course welcome to use the same value more than once as well: Format("X={0}, Y={1} (and yes, x really equals {0})", x, y)
Assuming values of x=3.14159265359
and y=12
, all the above patterns would yield the following results:
- “X=x”
- “X=3.14159265359”
- “X=3.14159265359, Y=12”
- “X=3.14159265359, Y=12 (and yes, x really equals 3.14159265359)”
You can include a formatting mask or instruction along with a placeholder. These bits are included within the curly brackets, separated from the placeholder index by a colon. It allows us for example to format data in a more readable fashion: Format("X={0:0.00}, Y={1} (x actually equals {0:R})
, which would yield “X=3.14, Y=12 (x actually equals 3.14159265359)”. The first time x
is inserted it is forcefully rounded to two decimal places. The second time x
is inserted the R
instruction is used. R
stands for “Roundtrip formatting” meaning there is guaranteed no loss of information during formatting. It shows the number as it really is.
There are loads and loads of standard and custom formatting instructions, some designed for numbers, others for dates or times, currency amounts, etc. etc.