user3322987
user3322987

Reputation: 63

Line break based on character found

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

Answers (1)

damirstuhec
damirstuhec

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

Related Questions