I’ve always felt that networking problems and concepts are useful in application programming as well, as the problems will appear again at a higher level. Escaping is just another one of them.
In networking, signals/packets have special sequences to indicate special conditions such as the end of a frame. However the same special sequence may appear in data. By escaping and the sequence in the data, the receiver will be able to interpret the packet and the data correctly.
At the application programming level, the simplest example is with a quoted String: “This String has “some” quotes.” The some is being quoted in a quoted String. Escaping typically defines an escape character, such as a backslash (\). Therefore when the quote is prefixed by a backslash, it is interpreted as a data quote. All other special characters can now be prefixed with a backslash to indicate it is a special character.
Using an escape character causes another problem: the backslash now cannot be represented, and requires escaping as well. Using yet another escape character may solve the current problem, but it causes the same problem again. The usual solution to this is to use the escape character itself to escape itself. Therefore a backslash is represented as a double backslash (\\).
Other common escaping examples include VB quotes (” becomes “”) and HTML entities (< becomes <). Thus the next time you encounter problems with data containing control sequences, think of this solution! 1. Escape all control sequences using an escape sequence. 2. Escape the escape sequence using itself.