I have a String : "Doe, John"
. How would I remove all of the text before the word "John" so that it would be "John"
.
CodePudding user response:
let str = "John, Doe"
let array = str.split(separator: ",")
print("\(array.last?.trimmingCharacters(in: .whitespaces) ?? "")")
prints
Doe
Program ended with exit code: 0
I would also recommend using the documentation Larme has provided in the comments