<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Unicode/Scalar/escaped(asASCII:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s7UnicodeO6ScalarV7escaped7asASCIISSSb_tF"
  },
  "title" : "escaped(asASCII:)"
}
-->

# escaped(asASCII:)

Returns a string representation of the Unicode scalar.

```
func escaped(asASCII forceASCII: Bool) -> String
```

## Parameters

`forceASCII`

Pass `true` if you need the result to use only
ASCII characters; otherwise, pass `false`.

## Return Value

A string representation of the scalar.

## Discussion

Scalar values representing characters that are normally unprintable or
that otherwise require escaping are escaped with a backslash.

```
let tab = Unicode.Scalar(9)!
print(tab)
// Prints " "
print(tab.escaped(asASCII: false))
// Prints "\t"
```

When the `forceASCII` parameter is `true`, a `Unicode.Scalar` instance
with a value greater than 127 is represented using an escaped numeric
value; otherwise, non-ASCII characters are represented using their
typical string value.

```
let bap = Unicode.Scalar(48165)!
print(bap.escaped(asASCII: false))
// Prints "밥"
print(bap.escaped(asASCII: true))
// Prints "\u{BC25}"
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)