Add more String extensions

This commit is contained in:
Christoph Hagen 2022-08-17 10:34:14 +02:00
parent 4793a5bb42
commit baf65d886f

View File

@ -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!
}
}