init(decoding:as:)
init<C, Encoding>(decoding codeUnits: C, as sourceEncoding: Encoding.Type) where C : Collection, Encoding : _UnicodeEncoding, C.Element == Encoding.CodeUnit
init<C, Encoding>(decoding codeUnits: C, as sourceEncoding: Encoding.Type) where C : Collection, Encoding : _UnicodeEncoding, C.Element == Encoding.CodeUnit
sSS8decoding2asSSx_q_mtcSlRzs16_UnicodeEncodingR_8CodeUnitQy_7ElementRtzr0_lufc
What are these?3HTZ3
import Swift
@frozen struct String
A Unicode string value that is a collection of characters.
protocol Collection<Element> : Sequence
A sequence whose elements can be traversed multiple times, nondestructively, and accessed by an indexed subscript.
associatedtype Element where Self.Element == Self.Iterator.Element
A type representing the sequence’s elements.
init()
Creates an empty string.
init(_ unicodeScalars: String.UnicodeScalarView)
Creates a string corresponding to the given collection of Unicode scalars.
init(_ utf8: String.UTF8View)
Creates a string corresponding to the given sequence of UTF-8 code units.
init(_ utf16: String.UTF16View)
Creates a string corresponding to the given sequence of UTF-16 code units.
init(_ c: Character)
Creates a string containing the given character.
init?(_ codeUnits: Substring.UTF8View)
Creates a String having the given content.
init?(_ codeUnits: Substring.UTF16View)
Creates a String having the given content.
init(_ content: Substring.UnicodeScalarView)
Creates a String having the given content.
init(_ substring: Substring)
Creates a new string from the given substring.
init(_ scalar: Unicode.Scalar)
init<S>(_ characters: S) where S : Sequence, S.Element == Character
Creates a new string containing the characters in the given sequence.
init<S>(_ other: S) where S : LosslessStringConvertible, S : Sequence, S.Element == Character
Creates a new string containing the characters in the given sequence.
init<T>(_ value: T) where T : LosslessStringConvertible
Creates an instance from the description of a given LosslessStringConvertible
instance.
init<T>(_ value: T, radix: Int = 10, uppercase: Bool = false) where T : BinaryInteger
Creates a string representing the given value in base 10, or some other specified base.
init(cString nullTerminatedUTF8: UnsafePointer<CChar>)
Creates a new string by copying the null-terminated UTF-8 data referenced by the given pointer.
init(cString nullTerminatedUTF8: UnsafePointer<UInt8>)
Creates a new string by copying the null-terminated UTF-8 data referenced by the given pointer.
init?<T>(codingKey: T) where T : CodingKey
init<Encoding>(decodingCString nullTerminatedCodeUnits: UnsafePointer<Encoding.CodeUnit>, as encoding: Encoding.Type) where Encoding : _UnicodeEncoding
Creates a new string by copying the null-terminated sequence of code units referenced by the given pointer.
init<Subject>(describing instance: Subject)
Creates a string representing the given value.
init<Subject>(describing instance: Subject) where Subject : TextOutputStreamable
Creates a string representing the given value.
init<Subject>(describing instance: Subject) where Subject : CustomStringConvertible
Creates a string representing the given value.
init<Subject>(describing instance: Subject) where Subject : CustomStringConvertible, Subject : TextOutputStreamable
Creates a string representing the given value.
init(from decoder: any Decoder) throws
init<Subject>(reflecting subject: Subject)
Creates a string with a detailed representation of the given value, suitable for debugging.
init(repeating repeatedValue: String, count: Int)
Creates a new string representing the given string repeated the specified number of times.
init(repeating repeatedValue: Character, count: Int)
Creates a string representing the given character repeated the specified number of times.
init(stringInterpolation: DefaultStringInterpolation)
Creates a new instance from an interpolated string literal.
init(stringLiteral value: String)
Creates an instance initialized to the given string value.
init(unsafeUninitializedCapacity capacity: Int, initializingUTF8With initializer: (UnsafeMutableBufferPointer<UInt8>) throws -> Int) rethrows
Creates a new string with the specified capacity in UTF-8 code units, and then calls the given closure with a buffer covering the string’s uninitialized memory.
init?<Encoding>(validating codeUnits: some Sequence, as encoding: Encoding.Type) where Encoding : _UnicodeEncoding
Creates a new string by copying and validating the sequence of code units passed in, according to the specified encoding.
init?<Encoding>(validating codeUnits: some Sequence<Int8>, as encoding: Encoding.Type) where Encoding : _UnicodeEncoding, Encoding.CodeUnit == UInt8
Creates a new string by copying and validating the sequence of code units passed in, according to the specified encoding.
init?(validatingCString nullTerminatedUTF8: UnsafePointer<CChar>)
Creates a new string by copying and validating the null-terminated UTF-8 data referenced by the given pointer.
static func decodeCString<Encoding>(_ cString: UnsafePointer<Encoding.CodeUnit>?, as encoding: Encoding.Type, repairingInvalidCodeUnits isRepairing: Bool = true) -> (result: String, repairsMade: Bool)? where Encoding : _UnicodeEncoding
Creates a new string by copying the null-terminated data referenced by the given pointer using the specified encoding.
static func decodeCString<Encoding>(_ cString: [Encoding.CodeUnit], as encoding: Encoding.Type, repairingInvalidCodeUnits isRepairing: Bool = true) -> (result: String, repairsMade: Bool)? where Encoding : _UnicodeEncoding
var codingKey: any CodingKey { get }
var count: Int { get }
The number of characters in a string.
var customMirror: Mirror { get }
A mirror that reflects the String
instance.
var debugDescription: String { get }
A representation of the string that is suitable for debugging.
var description: String { get }
The value of this string.
var endIndex: String.Index { get }
A string’s “past the end” position—that is, the position one greater than the last valid subscript argument.
var isContiguousUTF8: Bool { get }
Returns whether this string is capable of providing access to validly-encoded UTF-8 contents in contiguous memory in O(1) time.
var isEmpty: Bool { get }
A Boolean value indicating whether a string has no characters.
var startIndex: String.Index { get }
The position of the first character in a nonempty string.
var unicodeScalars: String.UnicodeScalarView { get set }
The string’s value represented as a collection of Unicode scalar values.
var utf16: String.UTF16View { get set }
A UTF-16 encoding of self
.
var utf8: String.UTF8View { get set }
A UTF-8 encoding of self
.
var utf8CString: ContiguousArray<CChar> { get }
A contiguously stored null-terminated UTF-8 representation of the string.
subscript(i: String.Index) -> Character { get }
Accesses the character at the given position.
subscript(r: Range<String.Index>) -> Substring { get }
static func + (lhs: String, rhs: String) -> String
static func += (lhs: inout String, rhs: String)
static func < (lhs: String, rhs: String) -> Bool
static func == (lhs: String, rhs: String) -> Bool
static func ~= (lhs: String, rhs: Substring) -> Bool
mutating func append(_ c: Character)
Appends the given character to the string.
mutating func append(_ other: String)
Appends the given string to this string.
mutating func append(contentsOf newElements: String)
mutating func append(contentsOf newElements: Substring)
mutating func append<S>(contentsOf newElements: S) where S : Sequence, S.Element == Character
Appends the characters in the given sequence to the string.
func distance(from start: String.Index, to end: String.Index) -> Int
Returns the distance between two indices.
func encode(to encoder: any Encoder) throws
Encodes this value into the given encoder.
func hasPrefix(_ prefix: String) -> Bool
func hasSuffix(_ suffix: String) -> Bool
func hash(into hasher: inout Hasher)
Hashes the essential components of this value by feeding them into the given hasher.
func index(_ i: String.Index, offsetBy distance: Int) -> String.Index
Returns an index that is the specified distance from the given index.
func index(_ i: String.Index, offsetBy distance: Int, limitedBy limit: String.Index) -> String.Index?
Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index.
func index(after i: String.Index) -> String.Index
Returns the position immediately after the given index.
func index(before i: String.Index) -> String.Index
mutating func insert(_ newElement: Character, at i: String.Index)
Inserts a new character at the specified position.
mutating func insert<S>(contentsOf newElements: S, at i: String.Index) where S : Collection, S.Element == Character
Inserts a collection of characters at the specified position.
func lowercased() -> String
Returns a lowercase version of the string.
mutating func makeContiguousUTF8()
If this string is not contiguous, make it so. If this mutates the string, it will invalidate any pre-existing indices.
func makeIterator() -> String.Iterator
func max<T>(_ x: T, _ y: T) -> T where T : Comparable
func min<T>(_ x: T, _ y: T) -> T where T : Comparable
@discardableResult mutating func remove(at i: String.Index) -> Character
Removes and returns the character at the specified position.
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
Replaces this string with the empty string.
mutating func removeSubrange(_ bounds: Range<String.Index>)
Removes the characters in the given range.
mutating func replaceSubrange<C>(_ subrange: Range<String.Index>, with newElements: C) where C : Collection, C.Element == Character
Replaces the text within the specified bounds with the given characters.
mutating func reserveCapacity(_ n: Int)
Reserves enough space in the string’s underlying storage to store the specified number of ASCII characters.
func uppercased() -> String
Returns an uppercase version of the string.
func withCString<Result>(_ body: (UnsafePointer<Int8>) throws -> Result) rethrows -> Result
func withCString<Result, TargetEncoding>(encodedAs targetEncoding: TargetEncoding.Type, _ body: (UnsafePointer<TargetEncoding.CodeUnit>) throws -> Result) rethrows -> Result where TargetEncoding : _UnicodeEncoding
mutating func withUTF8<R>(_ body: (UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R
Runs body
over the content of this string in contiguous memory. If this string is not contiguous, this will first make it contiguous, which will also speed up subsequent access. If this mutates the string, it will invalidate any pre-existing indices.
mutating func write(_ other: String)
Appends the given string to this string.
func write<Target>(to target: inout Target) where Target : TextOutputStream
Writes the string into the given output stream.
@frozen struct Index
A position of a character or code unit in a string.
@frozen struct Iterator
@frozen struct UTF16View
A view of a string’s contents as a collection of UTF-16 code units.
@frozen struct UTF8View
A view of a string’s contents as a collection of UTF-8 code units.
@frozen struct UnicodeScalarView
A view of a string’s contents as a collection of Unicode scalar values.
typealias Element = Character
typealias SubSequence = Substring
typealias UnicodeScalarIndex = String.UnicodeScalarView.Index
The index type for a string’s unicodeScalars
view.
init(cString nullTerminatedUTF8: String)
init(cString nullTerminatedUTF8: [CChar])
Creates a new string by copying the null-terminated UTF-8 data referenced by the given array.
init(cString nullTerminatedUTF8: [UInt8])
Creates a new string by copying the null-terminated UTF-8 data referenced by the given array.
init(cString nullTerminatedUTF8: inout CChar)
init(cString nullTerminatedUTF8: inout UInt8)
init<Encoding>(decodingCString nullTerminatedCodeUnits: String, as encoding: Encoding.Type) where Encoding : _UnicodeEncoding
init<Encoding>(decodingCString nullTerminatedCodeUnits: inout Encoding.CodeUnit, as encoding: Encoding.Type) where Encoding : _UnicodeEncoding
init<Encoding>(decodingCString nullTerminatedCodeUnits: [Encoding.CodeUnit], as encoding: Encoding.Type) where Encoding : _UnicodeEncoding
Creates a new string by copying the null-terminated sequence of code units referenced by the given array.
init?(validatingCString nullTerminatedUTF8: String)
init?(validatingCString nullTerminatedUTF8: [CChar])
Creates a new string by copying and validating the null-terminated UTF-8 data referenced by the given array.
init?(validatingCString nullTerminatedUTF8: inout CChar)
init?(validatingUTF8 cString: UnsafePointer<CChar>)
Creates a new string by copying and validating the null-terminated UTF-8 data referenced by the given pointer.
init?(validatingUTF8 cString: String)
init?(validatingUTF8 cString: [CChar])
Creates a new string by copying and validating the null-terminated UTF-8 data referenced by the given array.
init?(validatingUTF8 cString: inout CChar)
static func decodeCString<Encoding>(_ cString: inout Encoding.CodeUnit, as encoding: Encoding.Type, repairingInvalidCodeUnits isRepairing: Bool = true) -> (result: String, repairsMade: Bool)? where Encoding : _UnicodeEncoding
static func decodeCString<Encoding>(_ cString: String, as encoding: Encoding.Type, repairingInvalidCodeUnits isRepairing: Bool = true) -> (result: String, repairsMade: Bool)? where Encoding : _UnicodeEncoding
var characters: String { get set }
A view of the string’s contents as a collection of characters.
var customPlaygroundQuickLook: _PlaygroundQuickLook { get }
A custom playground Quick Look for the String
instance.
mutating func withMutableCharacters<R>(_ body: (inout String) -> R) -> R
Applies the given closure to a mutable view of the string’s characters.
typealias CharacterView = String
A view of a string’s contents as a collection of characters.
typealias IndexDistance = Int
A type that represents the number of steps between two String.Index
values, where one value is reachable from the other.