Add more String extensions
This commit is contained in:
parent
4793a5bb42
commit
baf65d886f
@ -36,4 +36,20 @@ extension String {
|
||||
let parts = components(separatedBy: separator)
|
||||
return parts.dropLast().joined(separator: separator) + content + separator + parts.last!
|
||||
}
|
||||
|
||||
func dropAfterFirst<T>(_ separator: T) -> String where T: StringProtocol {
|
||||
components(separatedBy: separator).first!
|
||||
}
|
||||
|
||||
func between(_ start: String, and end: String) -> String {
|
||||
dropBeforeFirst(start).dropAfterFirst(end)
|
||||
}
|
||||
}
|
||||
|
||||
extension Substring {
|
||||
|
||||
func between(_ start: String, and end: String) -> String {
|
||||
components(separatedBy: start).last!
|
||||
.components(separatedBy: end).first!
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user