---
title: "trimmingCharacters(in:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/trimmingcharacters(in:)"
---

# trimmingCharacters(in:)

Returns a new string made by removing from both ends of the receiver characters contained in a given character set.

## Declaration

```swift
func trimmingCharacters(in set: CharacterSet) -> String
```

## Parameters

- `set`: A character set containing the characters to remove from the receiver. set must not be nil.

## Return Value

Return Value A new string made by removing from both ends of the receiver characters contained in set. If the receiver is composed entirely of characters from set, the empty string is returned.

## Discussion

Discussion Use whitespaces or whitespacesAndNewlines to remove whitespace around strings.

## See Also

### Dividing Strings

- [components(separatedBy:)](foundation/nsstring/components(separatedby:)-238fy.md)
- [components(separatedBy:)](foundation/nsstring/components(separatedby:)-27x9g.md)
- [substring(from:)](foundation/nsstring/substring(from:).md)
- [substring(with:)](foundation/nsstring/substring(with:).md)
- [substring(to:)](foundation/nsstring/substring(to:).md)
