---
title: "addingPercentEscapes(using:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/addingpercentescapes(using:)"
---

# addingPercentEscapes(using:)

Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.

## Declaration

```swift
func addingPercentEscapes(using enc: UInt) -> String?
```

## Parameters

- `enc`: The encoding to use for the returned string. If you are uncertain of the correct encoding you should use doc://com.apple.foundation/documentation/Foundation/NSUTF8StringEncoding.

## Return Value

Return Value A representation of the receiver using encoding to determine the percent escapes necessary to convert the receiver into a legal URL string. Returns nil if encoding cannot encode a particular character.

## Discussion

Discussion It may be difficult to use this function to “clean up” unescaped or partially escaped URL strings where sequences are unpredictable. See CFURLCreateStringByAddingPercentEscapes(_:_:_:_:_:) for more information.

## See Also

### Related Documentation

- [addingPercentEncoding(withAllowedCharacters:)](foundation/nsstring/addingpercentencoding(withallowedcharacters:).md)
- [removingPercentEncoding](foundation/nsstring/removingpercentencoding.md)

### Deprecated

- [string(withCString:)](foundation/nsstring/string(withcstring:).md)
- [init(CString:)](foundation/nsstring/init(cstring:)-vkuo.md)
- [string(withCString:length:)](foundation/nsstring/string(withcstring:length:).md)
- [init(CString:length:)](foundation/nsstring/init(cstring:length:)-5ure3.md)
- [init(CStringNoCopy:length:freeWhenDone:)](foundation/nsstring/init(cstringnocopy:length:freewhendone:)-86dm2.md)
- [string(withContentsOfFile:)](foundation/nsstring/string(withcontentsoffile:).md)
- [init(contentsOfFile:)](foundation/nsstring/init(contentsoffile:).md)
- [string(withContentsOf:)](foundation/nsstring/string(withcontentsof:).md)
- [init(contentsOfURL:)](foundation/nsstring/init(contentsofurl:).md)
- [write(toFile:atomically:)](foundation/nsstring/write(tofile:atomically:).md)
- [write(to:atomically:)](foundation/nsstring/write(to:atomically:).md)
- [getCharacters(_:)](foundation/nsstring/getcharacters(_:).md)
- [cString()](foundation/nsstring/cstring().md)
- [lossyCString()](foundation/nsstring/lossycstring().md)
- [cStringLength()](foundation/nsstring/cstringlength().md)
