I have a problem and I am wondering if there is any smart workaround.
I need to pass a string through a socket to a web application. This string has three parts and I use the ‘|’ as a delimiter to split at the receiving application into the three separate parts.
The problem is that the ‘|’ character can be a character in any of the 3 separate strings and when this occurs the whole splitting action distorts the strings.
My question therefore is this:
Is there a way to use a char/string as a delimiter in some text while this char/string itself might be in the text?
The general pattern is to escape the delimiter character. E.g. when ‘|’ is the delimiter, you could use “||” whenever you need the character itself inside a string (might be difficult if you allow empty strings) or you could use something like ‘\’ as the escape character so that ‘|’ becomes “\|” and “\” itself would be “\\”