---
title: "addingPercentEncoding(withAllowedCharacters:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/stringprotocol/addingpercentencoding(withallowedcharacters:)"
---

# addingPercentEncoding(withAllowedCharacters:)

Returns a new string created by replacing all characters not in the specified set with percent-encoded characters.

## Declaration

```swift
func addingPercentEncoding(withAllowedCharacters allowedCharacters: CharacterSet) -> String?
```
