Problem:
I have a given string = "Hello @User Name and hello again @Full Name and this works"
Desired output: = ["@User Name, @Full Name"]
Code I have in Swift:
let commentString = "Hello @User Name and hello again @Full Name and this works"
let words = commentString.components(separatedBy: " ")
let mentionQuery = "@"
for word in words.filter({ $0.hasPrefix(mentionQuery) }) {
print(word) = prints out each single name word "@User" and "@Full"
}
Trying this:
if words.filter({ $0.hasPrefix(mentionQuery) }).isNotEmpty {
print(words) ["Hello", "@User", "Name".. etc.]
}
I'm stuck on how to get an array of strings with the full name = ["@User Name", "@Full Name"]
Would you know how?