提问人:Jessica Kimble 提问时间:11/16/2023 更新时间:11/17/2023 访问量:48
替换 String Array 的匹配项
Replacing occurrences of String Array
问:
这是我的阵列
["<h2>Some text, and some info.</h2>", "<h2>Another text</h2>"]
我需要让它看起来像这样
<h2>Some text, and some info.</h2><h2>Another text</h2>
我需要删除["
", "
"]
尝试调用数组extension
replcaingOccurances
[String]
extension Array where Element == String {
func replacingOccurrences(of target: String, with replacement: String, options: NSString.CompareOptions) -> Self
{
return self.map( { $0.replacingOccurrences(of: target, with: replacement, options: options) } )
}
}
背景:我正在将数据保存在html
array
Core Data
尝试使用扩展不会筛选任何匹配项
let result = ResultCoreDataManager.sharedInstance.getResults()
let filtered = result?.replacingOccurrences(of: "<[\"\"]\",\"\", \"", with: "", options: .regularExpression)
请帮忙?
答:
1赞
son
11/16/2023
#1
这是一个包含 2 个元素的字符串数组,那么为什么不直接使用 ?joined
let htmls = ["<h2>Some text, and some info.</h2>", "<h2>Another text</h2>"]
let output = htmls.joined()
print(output)
//<h2>Some text, and some info.</h2><h2>Another text</h2>
评论
description()