Skip to content
Swift

String API Reference

Swift's String — a value type representing a sequence of Unicode scalar values (extended grapheme clusters).

By EZ4Code Team

String

A Unicode string value that is a collection of characters. A value type bridged to NSString.

String.count -> Int

The number of characters (extended grapheme clusters) in the string.

Returns: Int

String.uppercased() -> String

Returns a new string made by replacing lowercase characters with uppercase ones.

Returns: String

String.lowercased() -> String

Returns a new string made by replacing uppercase characters with lowercase ones.

Returns: String

String.hasPrefix(_ prefix: String) -> Bool

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

Returns: Bool

String.hasSuffix(_ suffix: String) -> Bool

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

Returns: Bool

String.contains(_ other: String) -> Bool

Returns true if the string contains the given string or character.

Returns: Bool

String.split(separator: Character) -> [Substring]

Returns the longest possible subsequences of the string, in order, around the separator.

Returns: [Substring]

String.replacingOccurrences(of: String, with: String) -> String

Returns a new string in which all occurrences of a target string are replaced by another.

Returns: String

More Swift API References