Skip to content

Instantly share code, notes, and snippets.

@gchumillas
Created November 8, 2022 16:52
Show Gist options
  • Save gchumillas/2bce0cb3387879e8deba88a9d25ed906 to your computer and use it in GitHub Desktop.
Save gchumillas/2bce0cb3387879e8deba88a9d25ed906 to your computer and use it in GitHub Desktop.
extension String {
func leftTrimmed() -> Self {
guard let i = self.firstIndex(where: { !$0.isWhitespace }) else {
return ""
}
return "\(self[i...])"
}
func rightTrimmed() -> Self {
guard let i = self.lastIndex(where: { !$0.isWhitespace }) else {
return ""
}
return "\(self[...i])"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment