Generate Verbatim Text in C#

C

CapCity

We have an application that needs to read in a text file (SAS Source Code)
as a string, does text substitution with it, and runs a SAS process with
this string as a parameter. The problem is that the SAS source code has some
double quotes in it, and some of the substitutions are full file paths, with
the slashes.

So what we're feeding into the SAS processor is \"text\" instead of "text"
and C:\\Folder\\File.txt instead of C:\Folder\File.

Is there a way to get the string values to work as the verbatim literals do?
Without the escape characters? If there is, then I'm not using the correct
keywords to search on, because I can't find it.

Thanks in advance.
 
P

Peter Duniho

We have an application that needs to read in a text file (SAS Source
Code)
as a string, does text substitution with it, and runs a SAS process with
this string as a parameter. The problem is that the SAS source code has
some
double quotes in it, and some of the substitutions are full file paths,
with
the slashes.

So what we're feeding into the SAS processor is \"text\" instead of
"text"
and C:\\Folder\\File.txt instead of C:\Folder\File.

Sounds to me as though you're making the classic error of thinking that
the string the debugger shows you is character-for-character what's
actually in the string.

The debugger shows you a string that has stuff like that escaped. But the
string itself doesn't actually literally contain a backslash followed by a
quote or another backslash or whatever. It just has the escaped character
itself (the quote, backslash, etc.)

In other words, you don't need to do anything special to get the verbatim
text. Read the text into a string from a file, and the string will have
precisely the same text in it that the file has (or as near as is
possible, given any encoding conversion that might have
happened...normally there wouldn't be any limitations here though).

Pete
 
C

CapCity

Peter Duniho said:
Sounds to me as though you're making the classic error of thinking that
the string the debugger shows you is character-for-character what's
actually in the string.

The debugger shows you a string that has stuff like that escaped. But the
string itself doesn't actually literally contain a backslash followed by a
quote or another backslash or whatever. It just has the escaped character
itself (the quote, backslash, etc.)

In other words, you don't need to do anything special to get the verbatim
text. Read the text into a string from a file, and the string will have
precisely the same text in it that the file has (or as near as is
possible, given any encoding conversion that might have
happened...normally there wouldn't be any limitations here though).

Pete

Pete,

You're exactly right - thanks for straightening me out.

And thanks for calling it a "classic" error. Made me feel a little better
about my brain-lapse.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top