gpt4 book ai didi

包含特殊字符的 Swift 字符串

转载 作者:行者123 更新时间:2023-11-28 11:49:42 25 4
gpt4 key购买 nike

我让用户在 NSTextView 中输入多个字符串。

var textViewString = textView.textStorage?.string

打印字符串 ( print(textViewString) ),我得到一个多行字符串,例如:

hello this is line 1 

and this is line 2

我想要一个包含换行符的快速字符串表示。例如,我希望 print(textStringFlat) 打印:

hello this is line 1\n\nand this is line 2

我需要对 textViewString 做什么才能显示特殊字符?

最佳答案

如果您只想用文字字符 \n 替换换行符,请使用:

let escapedText = someText.replacingOccurrences(of: "\n", with: "\\n")

关于包含特殊字符的 Swift 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51995073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com