Latest 0.1.5
Homepage https://github.com/adle29/SwiftyStrings
License MIT
Platforms ios 8.0
Authors

SwiftyStrings is simple string manipulation extenson for Swift. The purpose of this library is to translate useful PHP string methods to Swift.

Contribution

Please feel free to contribute to the project. The goal is to convert as many useful php string methods into Swift methods in order to ease the complexity of the Swift string manipulaiton API.

Installation

SwiftyStrings is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "SwiftyStrings"

Usage

import SwiftyStrings

Methods

is_numeric()

"1".is_numeric() // True

length()

"Hello World".length() // 11

getChar()

"Captian America".getChar(0) // C

hexStringToInt()

"A".hexStringToInt(0) // 10

split()

"sushi,tacos,ramen".split(",") // ["sushi", "tacos", "ramen"]

indexOf()

"Life is like a box of chocolates.".indexOf(of: "box") // Swift.String.CharacterView.Index(_base: Swift.String.UnicodeScalarView.Index(_position: 15), _countUTF16: 1)

strstr()

"Life is like a box of chocolates.".strstr(haystack: "box") // box of chocolates.
"Life is like a box of chocolates.".strstr(haystack: "box", before_needle: true) // Life is like a box

strrev()

"Roses are Red."strrev() // .deR era sesoR

substr()

"To be or not to be- that is the question.".substr(9) // not to be- that is the question.
"To be or not to be- that is the question.".substr(9,13) //not
"To be or not to be- that is the question.".substr(r: 9..<13) //not

substr_count()

"RedRedYellowRedBlue".substr_count("(Red)[\w]*(Red)" \ 3

str_replace()

"Make war.".str_replace("war", "love") \ "Make love."

strpos()

"A Yellow Submarine.".strpos("Submarine") \ 9

preg_match()

"RedRedYellowRedBlue".preg_match("(Red)[\w]*(Red)") \ ["RedRedYellowRed", "Red", "Red"]

preg_replace()

"RedRedYellowRedBlue".preg_replace("(Red)", "Blue") \ BlueBlueYellowBlueBlue

preg_match_one_callback()

"RedRedYellowRedBlue".preg_replace_callback("(Red)[\w]*(Red)") { (matches) -> [String] in
    return [matches[0].str_replace("Red", "Bed")]
} // BedBedYellowBedBlue

Latest podspec

{
    "name": "SwiftyStrings",
    "version": "0.1.5",
    "summary": "SwiftyStrings is simple string manipulation extenson for Swift.",
    "description": "SwiftyStrings is simple string manipulation extenson for Swift. The purpose of this library is to translate useful PHP string methods to Swift. This library is helpful because the Swift API to manipulate strings is complicated and difficult to use when working with string parsing or manipulation projects.",
    "homepage": "https://github.com/adle29/SwiftyStrings",
    "license": "MIT",
    "authors": {
        "Abraham Adberstein": "[email protected]"
    },
    "source": {
        "git": "https://github.com/adle29/SwiftyStrings.git",
        "tag": "0.1.5"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Pod/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This