I have a very simple set of lines of code. It doesn't matter whether you run it under UIKit or SwiftUI. In SwiftUI, I have the following.
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Button("Click on me") {
let tabLine = "1\tAnthony James\t139.9"
var item = ""
let tabs = tabLine.components(separatedBy: "\t")
for tab in tabs {
item += "'\(tab)'"
}
print("\(item)")
}
}
}
}
So I have tab-separated values. And I want to separate them and quote each value either with an apostrophe or a double quotation mark.
In the case above, I get the following print.
'1''Anthony James''139.9'
That's exactly what I want. Now, I have an array of three of those guys like the following.
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Button("Click on me") {
let tabLine0 = "1\tAnthony James\t139.9"
let tabLine1 = "2\tKim Harbaugh\t181.4"
let tabLine2 = "3\tAnthony James\t212.4"
let tabTextLines = [tabLine0, tabLine1, tabLine2]
var strings = [String]()
for tabLine in tabTextLines {
var item = ""
let tabs = tabLine.components(separatedBy: "\t")
for tab in tabs {
item += "'\(tab)'"
}
strings.append(item)
}
print("\(strings)")
}
}
.frame(width: 360, height: 240)
}
}
And I get the following print.
This is a nightmare situation. Each value is quoted with an escaped apostrophe. I can't even remove the escapees with replacingOccurrences(of:with:). How does that happen when you have an array of strings? If I try quoting the values with a unicode character, things are the same. Is there a workaround? Muchos thankos.