Reputation: 3535
I am working on macOS, not iOS, XCode 11.
My app allows in a specific location to enter text. This text can be anything. Once done it exports a csv which will be passed to an external process i cannot influence.
The issue: the external process uses semicolon ";" as a separator (csv is separated differently). If the user writes semicolon the external process will fail. If I manually add an escaping backslash before each semicolon to the csv and then pass it to the external app it works.
What I need: having each semicolon escaped with ONE backslash in the final csv
What I tried
Appreciate any help
UPDATE: I also tried to set a double backslash like @Corbell mentioned but this leads in a double backslash in the exported CSV -> fail I also tried to set a single backslash by using its unicode character:
[NSString stringWithFormat:@"%C;",0x5C]; --> "\\;"
Also failed and produces two backslashes in the final CSV (where i need ONE only).
Upvotes: 2
Views: 213
Reputation: 3535
Solved. It was the CSV Parser that added additional escaping characters. Once solved that it worked like a charm.
Upvotes: 0
Reputation: 1393
In your stringByReplacingOccurencesOfString call, second parameter, try escaping your backslash with a backslash to make it a literal character to insert, i.e. @"\\;"
- otherwise the compiler thinks you're trying to specify @"\;"
as an escape sequence (backslash-semicolon) which is invalid.
Upvotes: 1