> For the complete documentation index, see [llms.txt](https://til.devjugal.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.devjugal.com/go/trim-whitespaces-from-string.md).

# Trim Whitespaces From String

To remove whitespaces from a string, we can use [`strings.TrimSpace`](https://pkg.go.dev/strings#TrimSpace) function. It would remove leading and trailing spaces from the string.

## Example

```go
myString := strings.TrimSpace(" Hello World! ") // "Hello World!"
```

***Source:*** [***YourBasic***](https://yourbasic.org/golang/trim-whitespace-from-string/)
