SwiftyStrings is simple string manipulation extenson for Swift. The purpose of this library is to translate useful PHP string methods to Swift.
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.
SwiftyStrings is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SwiftyStrings"import SwiftyStringsis_numeric()
"1".is_numeric() // Truelength()
"Hello World".length() // 11getChar()
"Captian America".getChar(0) // ChexStringToInt()
"A".hexStringToInt(0) // 10split()
"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 boxstrrev()
"Roses are Red."strrev() // .deR era sesoRsubstr()
"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) //notsubstr_count()
"RedRedYellowRedBlue".substr_count("(Red)[\\w]*(Red)" \\ 3str_replace()
"Make war.".str_replace("war", "love") \\ "Make love."strpos()
"A Yellow Submarine.".strpos("Submarine") \\ 9preg_match()
"RedRedYellowRedBlue".preg_match("(Red)[\\w]*(Red)") \\ ["RedRedYellowRed", "Red", "Red"]preg_replace()
"RedRedYellowRedBlue".preg_replace("(Red)", "Blue") \\ BlueBlueYellowBlueBluepreg_match_one_callback()
"RedRedYellowRedBlue".preg_replace_callback("(Red)[\\w]*(Red)") { (matches) -> [String] in
return [matches[0].str_replace("Red", "Bed")]
} // BedBedYellowBedBlue