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