根据找到的字符换行
我想通过“@”将UILabel中的电子邮件分成两行,例如:
abc123
@gmail.com
如果这个词在NSString *变量内,我该如何分解它? 我是否应该按字符搜索字符串,直到找到“@”?
你应该使用的components(separatedBy separator: String) -> [String]
在功能String
:
Swift :
let stringComponentsArray = yourString.components(separatedBy: "@")
Objective-C :
NSArray *stringComponentsArray = [yourStringObject componentsSeparatedByString:@"@"];
这将通过字符@将字符串分隔成一个String
组件数组。
上一篇: Line break based on character found
下一篇: break after a hyphen