The Problem: I often paste strings into Mathca which have many what I call "extender characters" --which may extend the character set." We know these have to be dealt with so Mathca can deal with the string without error.
Here is an example of such a string. The "extender characters" are the \ characters. (Happens to be a directory string pasted from W7.)
myString=
"C:\Users\NEW USER\Documents\Data Files General\Creative Write\Analysis incl Econ Trips etc\Write Econ Soc Chce Fin Trips\Mathca\Learn and How Tos\Projcts Apps Unoptimized\Gradebook12x3x12plus.nb"
Here is code which converts myString into something more clear to Mathca:
FromCharacterCode[
Insert[ToCharacterCode[
myString],92,
Position[ToCharacterCode[myString],92]]] (* 92 is the ascii code of \ *)
The code works It replaces all "\" by "\\".
But it generates many "Unknown string escape" errors (warning that the \ characters in the string enable the extended character set, etc.)
There needs to be (there must be!) a function which permits us to optionally suppress the control character potentiality of certain characters. Then I would simply enter:
ConstrainedString[myString,{list of characters to optionally constrain}]
Then I could use
ReplaceAll[myConstrainedString, "\"->"\\"]
I don't want to be blindsided by extender characters not relevant in my code if, in that code, those characters only have the literal meaning. I want a clean way of converting or manipulating strings which have "extender characters", so a longer list of functions will be available.
StringReplace["\a\b\c", "\\" -> "\\\\"]
complains that these areSyntax::stresc: Unknown string escape
. $\endgroup$"\a\b\c"
is a syntax error at the beginning. Or maybe it boils down to whose responsibility it is to differentiate"\a"
(two characters) and"\n"
(one character): should kernel tries to be smart or should users differentiate them when construct the string? $\endgroup$