Swiftpack.co - WengYuehTing/StringUtils as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by WengYuehTing.
WengYuehTing/StringUtils v1.0.2
A swift package for string utilities.
⭐️ 0
🕓 2 weeks ago
.package(url: "https://github.com/WengYuehTing/StringUtils.git", from: "v1.0.2")


In the release of Swift 5.5 there is still a lack of intuitive APIs for native type String. To simply access n-th character of a string, developers have to write the code like string[string.index(string.startIndex, offsetBy: n)] which is less readable and maintainable. Also, the performance of string interpolations using String.Index is a little bit confused, as it seems to convert to [Character] could always have performance benefits. Thus, this package aims to provide intuitive APIs for type String which get rids of String.Index and uses Int and Range<Int> to manipulate a string, such as:

let string = " hello world "
string[1]                 \\ "h"
string[1..<3]             \\ "he"
string.insert("h", at: 1) \\ " hhello world "
string.remove(at: 0)      \\ " "
string.trim()             \\ "hello world"
string.rtrim()            \\ " hello world"
string.ltrim()            \\ "hello world "
string.split(" ")         \\ ["hello", "world"]
string.contains("world")  \\ 7
string.base64Encoded()    \\ "IGhlbGxvIFdvcmxkIA=="
string.urlEncoded()       \\ "%20hello%20world%20"
string.md5()              \\ "c9708cb9a6b8d820eda83547a218f384"

let email = "username@gmail.com"
let pattern = "([A-Z0-9a-z._%+-]+)@([A-Za-z0-9.-]+\\.[A-Za-z]{2,64})"
email.matches(withPattern: emailPattern) \\ [["username@gmail.com", "username", "gmail.com"]]

Swift Package Manager

Using swift package manager for intergration by adding following description in Package.swift file:

.package(url: "https://github.com/WengYuehTing/StringUtils.git", .upToNextMajor(from: "1.0.0")),


Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

8 weeks ago

updated insert and remove apis

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics