trimmingSuffix(while:)
Returns a SubSequence
formed by discarding all elements at the end of the collection which satisfy the given predicate.
func trimmingSuffix(while predicate: (Element) throws -> Bool) rethrows -> SubSequence
Parameters
- predicate
A closure which determines if the element should be omitted from the resulting slice.
This example uses trimmingSuffix(while:)
to get a substring without the white space at the end of the string:
let myString = " hello, world "
print(myString.trimmingSuffix(while: \.isWhitespace)) // " hello, world"