contains(_:)
Returns true
iff other
is non-empty and contained within self
by case-sensitive, non-literal search.
func contains<T>(_ other: T) -> Bool where T : StringProtocol
Equivalent to self.rangeOfString(other) != nil
Returns true
iff other
is non-empty and contained within self
by case-sensitive, non-literal search.
func contains<T>(_ other: T) -> Bool where T : StringProtocol
Equivalent to self.rangeOfString(other) != nil
import Swift
import Foundation
protocol StringProtocol : BidirectionalCollection, Comparable, ExpressibleByStringInterpolation, Hashable, LosslessStringConvertible, TextOutputStream, TextOutputStreamable where Self.Element == Character, Self.Index == String.Index, Self.StringInterpolation == DefaultStringInterpolation, Self.SubSequence : StringProtocol
A type that can represent a string as a collection of characters.
@frozen struct Bool
A value type whose instances are either true
or false
.
var decomposedStringWithCanonicalMapping: String { get }
A string created by normalizing the string’s contents using Form D.
var decomposedStringWithCompatibilityMapping: String { get }
A string created by normalizing the string’s contents using Form KD.
var fastestEncoding: String.Encoding { get }
The fastest encoding to which the string can be converted without loss of information.
var precomposedStringWithCanonicalMapping: String { get }
A string created by normalizing the string’s contents using Form C.
var precomposedStringWithCompatibilityMapping: String { get }
A string created by normalizing the string’s contents using Form KC.
var removingPercentEncoding: String? { get }
A new string made from the string by replacing all percent encoded sequences with the matching UTF-8 characters.
var smallestEncoding: String.Encoding { get }
The smallest encoding to which the string can be converted without loss of information.
func addingPercentEncoding(withAllowedCharacters allowedCharacters: CharacterSet) -> String?
Returns a new string created by replacing all characters in the string not in the specified set with percent encoded characters.
func appending<T>(_ aString: T) -> String where T : StringProtocol
Returns a new string created by appending the given string.
func appendingFormat<T>(_ format: T, _ arguments: any CVarArg...) -> String where T : StringProtocol
Returns a string created by appending a string constructed from a given format string and the following arguments.
func cString(using encoding: String.Encoding) -> [CChar]?
Returns a representation of the string as a C string using a given encoding.
func canBeConverted(to encoding: String.Encoding) -> Bool
Returns a Boolean value that indicates whether the string can be converted to the specified encoding without loss of information.
func caseInsensitiveCompare<T>(_ aString: T) -> ComparisonResult where T : StringProtocol
Returns the result of invoking compare:options:
with NSCaseInsensitiveSearch
as the only option.
func commonPrefix<T>(with aString: T, options: String.CompareOptions = []) -> String where T : StringProtocol
Returns a string containing characters this string and the given string have in common, starting from the beginning of each up to the first characters that aren’t equivalent.
func compare<T>(_ aString: T, options mask: String.CompareOptions = [], range: Range<Self.Index>? = nil, locale: Locale? = nil) -> ComparisonResult where T : StringProtocol
Compares the string using the specified options and returns the lexical ordering for the range.
func completePath(into outputName: UnsafeMutablePointer<String>? = nil, caseSensitive: Bool, matchesInto outputArray: UnsafeMutablePointer<[String]>? = nil, filterTypes: [String]? = nil) -> Int
Interprets the string as a path in the file system and attempts to perform filename completion, returning a numeric value that indicates whether a match was possible, and by reference the longest path that matches the string.
func components(separatedBy separator: CharacterSet) -> [String]
Returns an array containing substrings from the string that have been divided by characters in the given set.
func enumerateLines(invoking body: @escaping (String, inout Bool) -> Void)
Enumerates all the lines in a string.
func enumerateSubstrings<R>(in range: R, options opts: String.EnumerationOptions = [], _ body: @escaping (String?, Range<Self.Index>, Range<Self.Index>, inout Bool) -> Void) where R : RangeExpression, R.Bound == String.Index
Enumerates the substrings of the specified type in the specified range of the string.
func folding(options: String.CompareOptions = [], locale: Locale?) -> String
Returns a string with the given character folding options applied.
func getBytes<R>(_ buffer: inout [UInt8], maxLength maxBufferCount: Int, usedLength usedBufferCount: UnsafeMutablePointer<Int>, encoding: String.Encoding, options: String.EncodingConversionOptions = [], range: R, remaining leftover: UnsafeMutablePointer<Range<Self.Index>>) -> Bool where R : RangeExpression, R.Bound == String.Index
Writes the given range
of characters into buffer
in a given encoding
, without any allocations. Does not NULL-terminate.
func getCString(_ buffer: inout [CChar], maxLength: Int, encoding: String.Encoding) -> Bool
Converts the String
’s content to a given encoding and stores them in a buffer.
func getLineStart<R>(_ start: UnsafeMutablePointer<Self.Index>, end: UnsafeMutablePointer<Self.Index>, contentsEnd: UnsafeMutablePointer<Self.Index>, for range: R) where R : RangeExpression, R.Bound == String.Index
Returns by reference the beginning of the first line and the end of the last line touched by the given range.
func getParagraphStart<R>(_ start: UnsafeMutablePointer<Self.Index>, end: UnsafeMutablePointer<Self.Index>, contentsEnd: UnsafeMutablePointer<Self.Index>, for range: R) where R : RangeExpression, R.Bound == String.Index
Returns by reference the beginning of the first paragraph and the end of the last paragraph touched by the given range.
func lengthOfBytes(using encoding: String.Encoding) -> Int
Returns the number of bytes required to store the String
in a given encoding.
func localizedCaseInsensitiveCompare<T>(_ aString: T) -> ComparisonResult where T : StringProtocol
Compares the string and the given string using a case-insensitive, localized, comparison.
func localizedCaseInsensitiveContains<T>(_ other: T) -> Bool where T : StringProtocol
Returns a Boolean value indicating whether the given string is non-empty and contained within this string by case-insensitive, non-literal search, taking into account the current locale.
func localizedCompare<T>(_ aString: T) -> ComparisonResult where T : StringProtocol
Compares the string and the given string using a localized comparison.
func localizedStandardCompare<T>(_ string: T) -> ComparisonResult where T : StringProtocol
Compares the string and the given string as sorted by the Finder.
func localizedStandardContains<T>(_ string: T) -> Bool where T : StringProtocol
Returns a Boolean value indicating whether the string contains the given string, taking the current locale into account.
func localizedStandardRange<T>(of string: T) -> Range<Self.Index>? where T : StringProtocol
Finds and returns the range of the first occurrence of a given string, taking the current locale into account. Returns nil
if the string was not found.
func maximumLengthOfBytes(using encoding: String.Encoding) -> Int
Returns the maximum number of bytes needed to store the String
in a given encoding.
func padding<T>(toLength newLength: Int, withPad padString: T, startingAt padIndex: Int) -> String where T : StringProtocol
Returns a new string formed from the String
by either removing characters from the end, or by appending as many occurrences as necessary of a given pad string.
func range<T>(of aString: T, options mask: String.CompareOptions = [], range searchRange: Range<Self.Index>? = nil, locale: Locale? = nil) -> Range<Self.Index>? where T : StringProtocol
Finds and returns the range of the first occurrence of a given string within a given range of the String
, subject to given options, using the specified locale, if any.
func rangeOfCharacter(from aSet: CharacterSet, options mask: String.CompareOptions = [], range aRange: Range<Self.Index>? = nil) -> Range<Self.Index>?
Finds and returns the range in the String
of the first character from a given character set found in a given range with given options.
func rangeOfComposedCharacterSequence(at anIndex: Self.Index) -> Range<Self.Index>
Returns the range in the String
of the composed character sequence located at a given index.
func rangeOfComposedCharacterSequences<R>(for range: R) -> Range<Self.Index> where R : RangeExpression, R.Bound == String.Index
Returns the range in the string of the composed character sequences for a given range.
func replacingCharacters<T, R>(in range: R, with replacement: T) -> String where T : StringProtocol, R : RangeExpression, R.Bound == String.Index
Returns a new string in which the characters in a specified range of the String
are replaced by a given string.
func replacingOccurrences<Target, Replacement>(of target: Target, with replacement: Replacement, options: String.CompareOptions = [], range searchRange: Range<Self.Index>? = nil) -> String where Target : StringProtocol, Replacement : StringProtocol
Returns a new string in which all occurrences of a target string in a specified range of the string are replaced by another given string.
func trimmingCharacters(in set: CharacterSet) -> String
Returns a new string made by removing from both ends of the String
characters contained in a given character set.
func substring(from index: Self.Index) -> String
Returns a new string containing the characters of the String
from the one at a given index to the end.
func substring(to index: Self.Index) -> String
Returns a new string containing the characters of the String
up to, but not including, the one at a given index.
func substring(with aRange: Range<Self.Index>) -> String
Returns a string object containing the characters of the String
that lie within a given range.