如何使用 swift 代码从 UITextView 中删除 \n\n?
How to remove \n\n from UITextView using swift code?
我让用户在 UITextView 中输入文本,然后使用此代码将其发送到 firebase
func sendDataToFirebase(){
let productID = self.ref.childByAutoId().key
let userID = Auth.auth().currentUser?.uid
let product = [ "productID" : productID,
"uid" : userID,
"details": self.txtProductDetails.text! as String
] as [String : Any]
self.ref.child("products").child(productID!).setValue(product)
}
如果用户输入的文本是多行的,它将转到 firebase 并具有 \n\n
因此,当我获取文本时,我得到的结果与 \n\n 相同。如何删除 \n\n textView 必须看起来井井有条的地方。
试试这个
func sendDataToFirebase(){
let productID = self.ref.childByAutoId().key
let userID = Auth.auth().currentUser?.uid
guard let text = self.txtProductDetails.text else{return}
let newText = text.replacingOccurrences(of: "\n\n", with: "")
let product = [ "productID" : productID,
"uid" : userID,
"details": newText
] as [String : Any]
self.ref.child("products").child(productID!).setValue(product)
}
我让用户在 UITextView 中输入文本,然后使用此代码将其发送到 firebase
func sendDataToFirebase(){
let productID = self.ref.childByAutoId().key
let userID = Auth.auth().currentUser?.uid
let product = [ "productID" : productID,
"uid" : userID,
"details": self.txtProductDetails.text! as String
] as [String : Any]
self.ref.child("products").child(productID!).setValue(product)
}
如果用户输入的文本是多行的,它将转到 firebase 并具有 \n\n
因此,当我获取文本时,我得到的结果与 \n\n 相同。如何删除 \n\n textView 必须看起来井井有条的地方。
试试这个
func sendDataToFirebase(){
let productID = self.ref.childByAutoId().key
let userID = Auth.auth().currentUser?.uid
guard let text = self.txtProductDetails.text else{return}
let newText = text.replacingOccurrences(of: "\n\n", with: "")
let product = [ "productID" : productID,
"uid" : userID,
"details": newText
] as [String : Any]
self.ref.child("products").child(productID!).setValue(product)
}