Reputation: 63
I want to break an email in a UILabel into two lines by "@" , for example:
abc123
@gmail.com
If the word is inside a NSString *variable, how can I break it? Should I search the string by character until I found "@"?
Upvotes: 2
Views: 116
Reputation: 6207
You should make use of components(separatedBy separator: String) -> [String]
function on String
:
Swift:
let stringComponentsArray = yourString.components(separatedBy: "@")
Objective-C:
NSArray *stringComponentsArray = [yourStringObject componentsSeparatedByString:@"@"];
This will separate your string by a character @ into a String
components array.
Upvotes: 1