ios - 根据找到的字符换行

标签 ios nsstring uilabel line-breaks word-wrap

我想通过“@”将 UILabel 中的电子邮件分成两行,例如:

abc123
@gmail.com

如果单词在 NSString *variable 中,我该如何打破它?我应该按字符搜索字符串直到找到“@”吗?

最佳答案

您应该在 String 上使用 components(separatedBy separator: String) -> [String] 函数:

swift :

let stringComponentsArray = yourString.components(separatedBy: "@")

objective-C :

NSArray *stringComponentsArray = [yourStringObject componentsSeparatedByString:@"@"];

这会将您的字符串用字符 @ 分隔成一个 String 组件数组

关于ios - 根据找到的字符换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22142291/

相关文章:

java - 如何使用if else语句和对话框?

ios - 如何在 iOS 中更新歌曲名称 shoutcast?

ios - 无法使用 NSString 初始化 NSMutableArray

ios - 在 iOS 中编写 UIButton 时避免代码重复

objective-c - 动态创建 iOS UILabel——我需要发布吗?

ios - 这种时间戳叫什么,我如何将它转换为人类可读的日期?

ios - UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName 不起作用

iphone - 将 UTF8 十六进制字符串转换为常规 UTF8 编码的 NSString

objective-c - 我为什么得到:从结果类型为char的函数返回const char *丢弃限定符

ios - 使用计时器功能设置标题时按钮文本闪烁,Swift