@IBOutlet weak var trialLabel: UILabel!
var string = "This is a trial text.Let us jump to a new line when the full stop is encountered.Hope it helps."
string = string.replacingOccurrences(of: ".", with: ".\n")
trialLabel.text = string
extension String{
func removeHtmlFromString(inPutString: String) -> String{
return inPutString.replacingOccurrences(of: ".", with: ".\n", options: .regularExpression, range: nil)
}
}
let str = "Lorem Ipsum is simply dummy text.Lorem Ipsum has been the industry's standard dummy text ever since the 1500."
let postDiscription = str!.removeHtmlFromString(inPutString: str!)
4条答案
按热度按时间l7mqbcuq1#
为标签创建了一个插座,并获取了一个由.""分隔的三个句子组成的字符串。所附图像中的内容将是此字符串。请尝试使用replacingOccurences()函数,如下所示。
检查https://developer.apple.com/documentation/foundation/nsstring/1412937-replacingoccurrences以获得进一步的参考。快乐编码!!
jchrr9hc2#
你可以通过UIClable的属性文本属性来实现,试着找到并用html换行符替换字符,然后把这个文本赋给UIClable属性文本。
可以将字符串替换为
ajsxfq5m3#
使用下面的代码// HTML标记删除方法
q7solyqu4#
可以在文本字符串中要创建换行符的位置添加\n。