SwiftyStrings 0.1.5

SwiftyStrings 0.1.5

测试已测试
语言 SwiftSwift
许可 MIT
发布最新发布2017 年 7 月
SwiftSwift 版本3.0
SPM支持 SPM

Abraham 维护。



  • Abraham Adberstein

SwiftyStrings

SwiftyStrings 是 Swift 的简单字符串操作扩展。该库的目的在于将有用的 PHP 字符串方法翻译成 Swift。

贡献

请随时为此项目贡献力量。目标是尽可能多的将有用的 PHP 字符串方法转换为 Swift 方法,以简化 Swift 字符串操作 API 的复杂性。

安装

SwiftyStrings 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "SwiftyStrings"

使用

import SwiftyStrings

方法

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