> ## Documentation Index
> Fetch the complete documentation index at: https://errand.nuvrel.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# trimspace

> Remove leading and trailing whitespace from a string.

`trimspace(str)` removes all leading and trailing whitespace characters from `str`, including spaces, tabs, and newlines.

## Signature

```
trimspace(str string) string
```

## Example

Read a project name from a configuration file and strip any accidental whitespace before using it in commands:

```hcl theme={null}
computed "project" {
  description = "Project name from the config file"
  expression  = trimspace(file(".project"))
}

task "build" {
  description = "Build the Docker image with the project name"
  commands = [
    "docker build -t ${computed.project}:latest .",
  ]
}
```

If `.project` contains `  myapp\n`, `computed.project` becomes `myapp`.

## Notes

* `trimspace` removes whitespace from both ends. It does not affect whitespace in the middle of the string.
* To remove only trailing newlines, use [`chomp`](/functions/string/chomp).
* To remove a specific set of characters, use [`trim`](/functions/string/trim).
