Skip to content

artemkin/StringEx.swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StringEx.swift

Useful Extensions of Swift String

String to number conversion

extension String {

    /// If the string represents an unsigned integer that fits into a specified
    /// unsigned integer type, returns the corresponding integer.
    /// This accepts strings that match the regular expression "[0-9]+" only.
    func toUInt()   -> UInt?
    func toUInt8()  -> UInt8?
    func toUInt16() -> UInt16?
    func toUInt32() -> UInt32?
    func toUInt64() -> UInt64?

    /// If the string represents an integer that fits into a specified integer type,
    /// returns the corresponding integer.  This accepts strings that match the regular
    /// expression "[-+]?[0-9]+" only.
    func toInt8()   -> Int8?
    func toInt16()  -> Int16?
    func toInt32()  -> Int32?
    func toInt64()  -> Int64?

    /// If the string represents a floating point number, returns the corresponding
    /// number as double. It is more strict than C strtod: whitespace characters
    /// and empty strings aren't allowed.
    func toDouble() -> Double?
}

About

Useful Extensions of Swift String

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published