trimSuffix(while:)
Mutates a BidirectionalCollection
by discarding all elements at the end of it which satisfy the given predicate.
mutating func trimSuffix(while predicate: (Element) throws -> Bool) rethrows
Parameters
- predicate
A closure which determines if the element should be removed from the string.
This example uses trimSuffix(while:)
to remove the white space at the beginning of the string:
let myString = " hello, world "
myString.trimSuffix(while: \.isWhitespace)
print(myString) // " hello, world"