# Useful helper functions

### Concatenate two strings

```handlebars
{{ concat '<string1>' '<string2>' }}
```

### Search and replace text in a string

```handlebars
{{ replace '<string-to-search>' '<string-to-replace>' '<replacement-string>' }}
```

### Create an array from a delimited string

This can be particularly useful when dealing with the results of a JSONPath query that returns an array, as these are space delimited strings of values.

```handlebars
{{ split '<delimited-string>' '<delimiter>' }}
```

### Change the HTTP response code

If you are following a pattern where you want a single request/response pair to return different HTTP response codes based on the outcome of logic, then you can do that using the following function:

```handlebars
{{ setStatusCode <any-valid-http-response-code> }}
```

### Set the value of an HTTP response header

You can set the value of an HTTP header dynamically from script:

```handlebars
{{ setHeader '<header-name>' '<new-value>'}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloud.hoverfly.io/create-simulations/using-templating-in-simulations/useful-helper-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
