Properly escaping a string with double quotes and semicolons

I need to check a line read from a file against the following string:

“Buchungstag”;“Umsatztag”;“Vorgang”;“Referenz”;“Buchungstext”;“Umsatz in EUR”;

I already found out that this

strTableHeaderLine = """Buchungstag"""

works and gives me “Buchungstag” as expected result. But this throws an error:

strTableHeaderLine = """Buchungstag";""""

However, constructing the string like this:

strTableHeaderLine = """Buchungstag""" + ";"

works. But is there another way to escape the " and ; signs in the string without re-constructing with + ?

Do you want to load a text file contents with delimiter ?

Should be

strTableHeaderLine = “”“Buchungstag”“;”

Yes. It’s a csv text file where each data field is delimited with ";". I’m parsing the file line by line and the line mentioned in the op is a header line I want to skip. However, my idea ist to use this as a means of ensuring the csv file still uses the same sequence of data.

@Kem_Tekinay 's suggestion is the right one.

Was a good hint. So I ended up escaping

“Buchungstag”;“Umsatztag”;“Vorgang”;“Referenz”;“Buchungstext”;“Umsatz in EUR”;

like this:

"""Buchungstag"";""Umsatztag"";""Vorgang"";""Referenz"";""Buchungstext"";""Umsatz in EUR"";"

Thanks for your help!

If you can use the constant editor in the IDE, you don’t have to escape the values you save through that!

3 Likes