-1

我在 UITextView 中输入文本数据。我正在向 UITextView 添加多行。我从 TextView 得到的输出如下: Optional("Line1 line2 Line3"). 但我想打印出来如下:“Line1\nLine\2Line\3”。所以当我添加行文本时,我想看到输出 \n

我不希望它是可选的,但是 var text: String! 当我这样做时, Optional 没有出现,但是这次 \n 消失了。我想在行上查看 \n 输出

 @IBOutlet weak var textInputArea: UITextView!
  var text : String?
  text = textInputArea.text
        var new = text?.replacingOccurrences(of: "\\n", with: "\n", options: .regularExpression)
        let jsString = "createText('\(newString)')"
4

1 回答 1

0

如果你想得到的打印结果textline1\nline2\nline3

let text = "line1" + "\\n" +  "line2" +  "\\n" + "line3"
 print (text)

输出:

line1\nline2\nline3
于 2020-07-05T20:20:32.213 回答