簡體   English   中英

包含特殊字符的Swift字符串

[英]Swift String including Special Characters

我有一個用戶在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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM