新行命令 ( ) 不适用于 Firebase Firestore 数据库字符串 [英] New Line Command ( ) Not Working With Firebase Firestore Database Strings
问题描述
我正在使用 Swift 制作应用程序,并且正在使用 Firebase Firestore.Firestore 是一个数据库,其中包含一些我放入 UILabel
的字符串.对于我的一些字符串,我使用了换行命令(或
)
.所以我的一些字符串看起来像这样:
I'm making an app with Swift and I'm using Firebase Firestore. Firestore is a database that has some strings that I put into a UILabel
. With some of my strings, I am using the new line command (or
)
. So some of my strings look like this:
"This is line one
This is line two
This is line three"
但是,每当检索到该字符串时,它都会添加到 UILabel
并显示如下...
But, whenever that string is retrieved, it's addetoto the UILabel
and appears like this...
这是第一行 这是第二行 这是第三行
This is line one This is line two This is line three
...什么时候应该是这样...
...when it should be like this...
这是第一行
这是第二行
这是第三行
我假设
不适用于来自数据库的字符串?我试过用 \n
进行双重转义.有没有人解决这个问题?
I'm assuming that
does not work with strings coming from a database? I've tried double escaping with \n
. Does anyone have a fix for this?
这是我正在使用的代码...
Here is the code that I am using...
database.collection("songs").whereField("storyTitle", isEqualTo: "This is the story header").getDocuments { (snapshot, error) in
for document in (snapshot?.documents)! {
self.storyBodyLabel.text = (document.data()["storyBody"] as? String)!
}
}
推荐答案
我明白了.我只是简单地替换了字符 "来自我使用换行命令收到的字符串.
I got it. I simply just replaced the character " " from the string that I was receiving with the newline command.
label.text = stringRecived.replacingOccurrences(of: "
", with: "
")
因为我手动输入了我的字符串并给了 Firebase 一个类似的字符串第一行
第二行
第三行"
我正在替换
"用
"但是如果你给 Firebase 一个像
Because I manually typed out my string and gave Firebase a string like
"Line one
line two
line three"
I am replacing "
" with "
" But if you give Firebase a string like
"Line one
Line two
Line three"
Firebase 将这些返回值替换为 "\n"
从而制作代码
Firebase replaces those returns with "\n"
therfore making the code
label.text = stringRecived.replacingOccurrences(of: "\n", with: "
")
希望有帮助!
这篇关于新行命令 ( ) 不适用于 Firebase Firestore 数据库字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!