Grasshopper format component

Does somebody has a website on which I can see how to use the ‘Format component?’
I cannot find how to combine text nor format it.

The Expression component demonstrates how it’s done: ‘Math | Script | Expression’

Format("{0}, {1}", x, y)

or:

Format("{0} = {1}", x, y)

The same “expression” can also be used in the Evaluate component: ‘Math | Script | Evaluate’

2 Likes

Thank you Joseph :smiley:

What I also would like to know if there is a site or something which explains all the { " and ,x,y)

I cannot find a website which explains it more broadly in order for me to do more complex things with it.

Do you might know a website for that, with tutorials for making those “expressions?”

Kind regards,
Owl

Hi @ForestOwl,

In order to understand Format, you need to learn about string concatenation, which is an old practice used in computer programming to compose strings from various data types (i.e. other strings, ints, floats, etc.).
Format describes one approach to string concatenation.

Let’s see how it’s used in Python to get a better understanding:

name = "Bello"
age = 10
size = 1.53

print "My dog {0} is {1} years old and measures {2:.1f} meters.\n".format(name, age, size)
>>> 'My dog Bello is 10 years old and measures 1.5 meters.'

Here {num} describes an insertion point for data into the string. The number between the brackets refers to the order that the insertion items are passed to .format() and is optional.
:.1f declares that you want to format a float with only a single decimal place (even if the initial float has more. \n simply means new line.

In Grasshopper, the same example would look like this:

2 Likes

I’m not sure how it can be explained any simpler than this:

Example:

You can zoom in to add more inputs to both Expression and Evaluate, and rename them as you please.

1 Like