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

# StringProtocol Implementations

## Topics

### Structures

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

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

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

### Operators

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

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

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

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

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

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

### Initializers

[`init(cString: UnsafePointer<CChar>)`](/documentation/Swift/Substring/init(cString:))

Creates a string from the null-terminated, UTF-8 encoded sequence of
bytes at the given pointer.

[`init<C, Encoding>(decoding: C, as: Encoding.Type)`](/documentation/Swift/Substring/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/Substring/init(decodingCString:as:))

Creates a string from the null-terminated sequence of bytes at the given
pointer.

### Instance Properties

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

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

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

### Instance Methods

[`func hasPrefix<Prefix>(Prefix) -> Bool`](/documentation/Swift/Substring/hasPrefix(_:))

Returns a Boolean value indicating whether the string begins with the
specified prefix.

[`func hasSuffix<Suffix>(Suffix) -> Bool`](/documentation/Swift/Substring/hasSuffix(_:))

Returns a Boolean value indicating whether the string ends with the
specified suffix.

[`func hash(into: inout Hasher)`](/documentation/Swift/Substring/hash(into:))

Hashes the essential components of this value by feeding them into the
given hasher.

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

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

[`func withCString<Result, E>((UnsafePointer<CChar>) throws(E) -> Result) throws(E) -> Result`](/documentation/Swift/Substring/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/Substring/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)