Created
November 8, 2022 16:52
-
-
Save gchumillas/2bce0cb3387879e8deba88a9d25ed906 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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