<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/String/StringProtocol-Implementations",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "StringProtocol Implementations"
}
-->

# StringProtocol Implementations

## Topics

### Structures

[`struct UTF16View`](/documentation/Swift/String/UTF16View)

A view of a string’s contents as a collection of UTF-16 code units.

[`struct UTF8View`](/documentation/Swift/String/UTF8View)

A view of a string’s contents as a collection of UTF-8 code units.

[`struct UnicodeScalarView`](/documentation/Swift/String/UnicodeScalarView)

A view of a string’s contents as a collection of Unicode scalar values.

### Operators

[`static func != <RHS>(Self, RHS) -> Bool`](/documentation/Swift/String/!=(_:_:)-frzf)

[`static func == <RHS>(Self, RHS) -> Bool`](/documentation/Swift/String/==(_:_:)-8kzxf)

[`static func > <RHS>(Self, RHS) -> Bool`](/documentation/Swift/String/_(_:_:)-6o7qv)

[`static func < <RHS>(Self, RHS) -> Bool`](/documentation/Swift/String/_(_:_:)-8d1wy)

[`static func <= <RHS>(Self, RHS) -> Bool`](/documentation/Swift/String/_=(_:_:)-5y22v)

[`static func >= <RHS>(Self, RHS) -> Bool`](/documentation/Swift/String/_=(_:_:)-nd86)

### Initializers

[`init(cString: UnsafePointer<CChar>)`](/documentation/Swift/String/init(cString:)-2p84k)

Creates a new string by copying the null-terminated UTF-8 data referenced
by the given pointer.

[`init<C, Encoding>(decoding: C, as: Encoding.Type)`](/documentation/Swift/String/init(decoding:as:))

Creates a string from the given Unicode code units in the specified
encoding.

[`init<Encoding>(decodingCString: UnsafePointer<Encoding.CodeUnit>, as: Encoding.Type)`](/documentation/Swift/String/init(decodingCString:as:)-8yowf)

Creates a new string by copying the null-terminated sequence of code units
referenced by the given pointer.

### Instance Properties

[`var unicodeScalars: String.UnicodeScalarView`](/documentation/Swift/String/unicodeScalars)

The string’s value represented as a collection of Unicode scalar values.

[`var utf16: String.UTF16View`](/documentation/Swift/String/utf16)

A UTF-16 encoding of `self`.

[`var utf8: String.UTF8View`](/documentation/Swift/String/utf8)

A UTF-8 encoding of `self`.

### Instance Methods

[`func hasPrefix(String) -> Bool`](/documentation/Swift/String/hasPrefix(_:))

[`func hasSuffix(String) -> Bool`](/documentation/Swift/String/hasSuffix(_:))

[`func lowercased() -> String`](/documentation/Swift/String/lowercased())

Returns a lowercase version of the string.

[`func uppercased() -> String`](/documentation/Swift/String/uppercased())

Returns an uppercase version of the string.

[`func withCString<Result, E>((UnsafePointer<Int8>) throws(E) -> Result) throws(E) -> Result`](/documentation/Swift/String/withCString(_:))

Calls the given closure with a pointer to the contents of the string,
represented as a null-terminated sequence of UTF-8 code units.

[`func withCString<Result, TargetEncoding, E>(encodedAs: TargetEncoding.Type, (UnsafePointer<TargetEncoding.CodeUnit>) throws(E) -> Result) throws(E) -> Result`](/documentation/Swift/String/withCString(encodedAs:_:))

Calls the given closure with a pointer to the contents of the string,
represented as a null-terminated sequence of code units.

---

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)