The Mystery of an Array of Strings and Escaped Characters

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.

What output do you want when you print the array of strings?

I guess that printing an array is using the elements' debugDescription, rather than their description. Or something of that sort. If you want a particular format you should write explicit code to do that.

I need to quote each value with either an apostrophe or a double quotation mark, not an escaped one.

Your values are quoted with apostrophes.

The apostrophes are being escaped when you print the array.

What are you really trying to achieve here? I imagine that printing the array of strings is not your final objective.

Mistake... I meant to leave a comment.

Don't write comments, they are hard to view.

If I try to use an SQL command with a string quoted with apostrophes in order to insert initial values to an SQLite database file, SQLite seems to see escaped apostrophes rather than apostrophes as SQLite gives me an error.

How are you using SQLite?

You should never form SQL queries by joining strings together'); drop table users;

The Mystery of an Array of Strings and Escaped Characters
 
 
Q