String
extension String: RawRepresentable
extension String: PathAppendable
-
Declaration
Swift
public init?(rawValue: String) -
Declaration
Swift
public var rawValue: String { get } -
Returns a localized representation of the string.
Seealso
`NSLocalizedString.
Declaration
Swift
func localized(withArguments arguments: CVarArg..., bundle: Bundle = Bundle.main) -> StringParameters
bundleBundle were to search for localization.
argumentsFormatting arguments.
-
Returns a the formatted string.
Seealso
String.init(format:arguments:).Declaration
Swift
func format(with arguments: CVarArg...) -> StringParameters
argumentsFormatting arguments.
-
Returns an NSAttributedString with the same content as self but with the attributes specified for each first appearance of substrings passed.
Seealso
NSMutableAttributedString.addAttributes(_:range:)
Declaration
Swift
func format(withAttributes attrs: [String : [NSAttributedString.Key : Any]]) -> NSAttributedStringParameters
attributesA dictionary that specifies the attributes to add to the substring specified. The attributes should be specified with a dictionary itself in the same format required by the NSAttributedString. The possible keys are specified in
NSAttributedString.h(likeNSFontAttributeName). -
Builds an NSURL from a string.
Declaration
Swift
var url: URL? { get } -
Checks if the string has spaces or not.
Declaration
Swift
var hasSpaces: Bool { get } -
Checks if a string is a valid email or not.
Declaration
Swift
func isValidEmail() -> Bool -
Returns a copy of the string without its leading and trailing whitespace and newlines.
Declaration
Swift
var trimmed: String { get } -
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.
Seealso
stringByReplacingOccurrencesOfString().Declaration
Swift
func replacing(_ target: String, with replacement: String, options: NSString.CompareOptions = .literal, range: Range<Index>? = .none) -> StringParameters
targetThe string to replace.
withThe replacement.
optionsThe comparing options. Default: LiteralSearch
rangeThe range of the string to search.
-
Returns a new string without whitespaces.
Declaration
Swift
var withoutWhiteSpaces: String { get } -
Returns true if the string is not empty, false if not.
Declaration
Swift
var isNotEmpty: Bool { get } -
Returns a new string that contains the same as self except for the given
suffix. If it doesn’t have the suffix, it returns the same as self. If it has the suffix more than one time, it just removes the last occurence of it.The comparison is both case sensitive and Unicode safe.
Seealso
hasSuffix.Declaration
Swift
func remove(suffix: String) -> String -
Returns a new string that contains the same as self except for the given
prefix. If it doesn’t have the prefix, it returns the same as self. If it has the prefix more than one time, it just removes the first occurence of it.The comparison is both case sensitive and Unicode safe.
Seealso
hasPrefix.Declaration
Swift
func remove(prefix: String) -> String -
Returns UIImage drawing of the string, it’s recomended for using emojis as images, but it can be used with any string.
Declaration
Swift
func toImage(fontSize: CGFloat) -> UIImage?Parameters
fontSizeCGFloat, size of the font to use on the represented string.
-
Returns UIImage drawing of the string, it’s recomended for using emojis as images, but it can be used with any string.
Declaration
Swift
func toImage(font: UIFont) -> UIImage?Parameters
fontUIFont to apply to the drawn string.
-
Repeats a string multiple times.
Declaration
Swift
static func * (lhs: String, rhs: Int) -> StringParameters
lhsstring to repeat.
rhsnumber of times to repeat string.
-
Repeats a string multiple times.
Declaration
Swift
static func * (lhs: Int, rhs: String) -> StringParameters
lhsnumber of times to repeat string.
rhsstring to repeat.
String Extension Reference