Skip to main content
All CollectionsSupport
Replacing text on the fly
Replacing text on the fly

Using the sprintf filter

Chris Coleman avatar
Written by Chris Coleman
Updated over a week ago

The sprintf filter allows you to substitute variables inside of a text string.

For example, if you are calling an external API, and need to replace part of that API's URL with one of your environment variables, this can be a great way to do it.

The first example shows how to use variable substitution with a number using %d.

Example: we have a text value of hello world %d and apply the sprintf filter, it becomes hello world 54321.

The second example will replace %s with text:

Example: we have a text value of hello world %s and apply the sprintf filter, it becomes hello world anything.

We can use multiple arguments on the sprintf filter to replace any number of values. In the example below we have 2 %d and 2 %s. The first %d is equivalent to the first argument of 123. The second %d is equivalent to the second argument of 789. The first %s is equivalent to the first argument of hi. The first %s is equivalent to the second argument of end.

This example becomes: 123 hello 789 world hi this is the end

Did this answer your question?