I am running a VBA program from SAS. The SAS code for this basically looks like:
%let worksheet =&i; *worksheet number;
%let xlsfile = %STR(""C:\Data\Excel Workbook.xlsx"");
%let csvfile = %STR(""C:\Data\CSV File..csv"");
x 'cd "C:\Data\MN2013\Alignment\Data\SAS Programs"';
x "XlsWsToCsv.vbs &xlsfile &worksheet &csvfile";
I need to be able to include two double quotes (i.e. "") at the beginning and end of the file paths in the xlsfile and csvfile for the VBA program to recognize the spaces in the file paths and run correctly.
MY PROBLEM:
I run this in SAS Enterprise Guide using SAS 9.3. In my log, directly after the variable definition is read in, the double quotes are underlined in red (usually indicating an error) with the number 49 below. There is no error message, but instead, in green I get the following note:
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
release. Inserting white space between a quoted string and the succeeding
identifier is recommended.
To me, this says SAS is reading these double quotes. They are somehow only partially being masked. My VBA program runs, so I could continue with this; but I like clean error logs. Does anyone have any recommendations for how to completely mask my xlsfile and csvfile variables? I've tried using %STR (as shown in my example above), %BQUOTE, %SUPERQ, and a few other things to make this work.
Those pesky error messages! You were very close, but try this syntax instead:
%let xlsfile = %STR("")C:\Data\Excel Workbook.xlsx%STR("");
%let csvfile = %STR("")C:\Data\CSV File..csv%STR("");
Double double quotes inside double quotes resolve to a single double quote character, ie...
x """c:\program files\office\excel.exe"" stuff stuff stuff ""stuff"" stuff";
should work just fine. Don't worry about the 'identifier' message, that's largely saying something like
"01JAN2013"d
could be possible with other things. You can add a space after the last " if it's a problem to have that in the log.
Related
In my program we originally were using Java with Preview Features enabled, which gave as a feature to use String blocks defined in between three double quotes. For example:
String s = """
Line one
Line two
""";
Now, we decided to go back to Java 14 and I need to replace those with regular String declaration in all project (which is around ~1000 occurrences). Is there a way to do that in bulk?
String s = "Line one\n"+
"Line two\n";
You can run the inspection "Text block can be replaced with regular string literal" inspection on your code using the "Run Inspection by Name" action. It has a quick fix to do the conversion for you.
So I want to echo out a line which contains just three double quotes. If I print two double quotes it just works fine and prints it (I believe the reason is that there is a corresponding closing quote) and double quotes in multiples of 2 work just fine but I'm unable to echo an odd number of them.
And from my searching the escape sequence character for double quote is double quote itself and it isn't getting me the desired result.
The command I'm running:
echo Item.Subject = Replace(Item.Subject, """, "-")>> try.xyz
expecting """ with this.
I've tried
"\""
"\\""
"^""
I am generating a bas file for importing in Outlook. And MC ND has corrected my mistake in the VBA file that I'm generating too. The proper way is to print 4 double quotes to do the escaping for the double quote from VBA script point of view and hence normal printing of 4 double quotes would solve my problem. The second double quote would be to escape the third one and the first and the last are to mention the replacement string from MC ND's answer.
Thanks a lot MC ND you've enlightened me. :-P
PS:
MC ND has given a much detailed explanation than this question deserved, so I extended the question.
Assumption: your batch code is generating a vbs file (or similar)
Your problem is not to echo the three quotes. Your problem is that in VBScript a double quote enclosed in double quotes needs to be escaped (from the vbs point of view), and to do so you need to double it, that is, you need not three but four quotes, the two that delimit the string and the two that means a escaped double quote
>>"try.xyz" echo Item.Subject = Replace(Item.Subject, """", "-")
note: I've moved the redirectioin to the start of the line to avoid problems with lines that could end in digits that could be parsed as a request to redirect a specific numbered stream
Assumption: Your code is NOT generating a vbs file and the quote escaping is what you indicate.
Then your problem is that the odd number of quotes is fooling the batch parser that keep an unclosed string that will include the redirection inside the data to echo, instead of writing to the output file
You can change the redirection to the start of the line as in the previous sample (at in this case it will work, the echo is still not correct), or, you can escape (from the batch point of view) the first quote so it is not considered double quote and to end with a properly quoted string, not including the redirection in the output
>>"try.xyz" Item.Subject = Replace(Item.Subject, """, "-")
echo Item.Subject = Replace(Item.Subject, ^""", "-") >> "try.xyz"
rem Best use both
>>"try.xyz" Item.Subject = Replace(Item.Subject, ^""", "-")
Why not to escape the inner quote? As it already is inside a quoted string, the escape will fail. We can escape the first or the last (in this case), not the inner one.
Assumption: Your code is not enclosed in parenthesis (for, if, ... ) inside the batch code
Then your code do not have any other problem,BUT if the assumption is wrong, then there is an additional problem. The closing parenthesis you are echoing will be seen by the batch parser as the closing parenthesis of the current block. To avoid it, you need to escape (from the batch parser point of view) the closing parenthesis.
(
....
>>"try.xyz" echo Item.Subject = Replace(Item.Subject, """", "-"^)
....
)
In TF2 scripting, there is a simple command, echo. This simply logs a message to the console. It can be used with or without double quotes. However, I want to be able to log something to the console involving double quotes--say, the string He said, "nope.". In conventional programming, one would escape the quotes, as so:
echo "He said, \"nope.\""
However, in the TF2 console, this writes:
He said, \ nope.\
Is there a way to use quotes in echo and related commands? (E.g. say)
It's not possible to output double quotes using echo or say, only single quotes. (source) (In fact whenever you type double quotes into regular chat they're automatically changed into single quotes. I don't know why this limitation exists, I'd have to dig around.)
I know this is a very old thread, but in case anyone else is trying to find a fix for this and found this post, let me provide an example of how to use single quotes. I had an alias for switching crosshairs, as such:
alias "default" "cl_crosshair_blue 255; cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_file "" "
This is to change the color of my crosshair, but more importantly, reset my crosshair to the "None" in options, letting the crosshair change depending on weapon, as I like most of the default crosshairs- but it would fail at the quotation mark immediately after "file", simply changing the colors and nothing more.
Using single quotes fixes this. Using ALT+0145 and ALT+0146 gives you the starting and ending single quotes (respectively) that you need. Replacing those two double quotes after "file" with the single quotes made the command work as intended.
alias "default" "cl_crosshair_blue 255; cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_file ‘’ "
So anytime you absolutely need to use a set quotation marks twice in a command, just use single quotes.
I've made some good progress with my first attempt at a program, but have hit another road block. I'm taking standard output (as a string) froma console CMD window (results of dsquery piped to dsget) and have found small rectangles in the output. I tried using Regex to clean the little bastards but it seems they are related to the _ (underscore), which I need to keep (to return 2000/NT logins). Odd thing is - when I copy the caharcter and paste it into VS2K10 Express it acts like a carrige return??
Any ideas on finding out what these little SOB's are -- and how to remove them?
Going to try using /U or /A CMD switch next..
The square is often just used whenever a character is not displayable. The character could very well be a CR. You can use a Regular Expression to just get normal characters or remove the CR LF characters using string.replace.
You mentioned that you are using the string.replace function, and I am wondering if you are replacing the wrong character or something like that. If all your trying to do is remove a carriage return I would skip the regular expressions and stick with the string.replace.
Something like this should work...
strInputString = strInputString.replace(chr(13), "")
If not could you post a line or two of code.
On a side note, this might give some other examples....
Character replacement in strings in VB.NET
I am trying to use a copy command for Windows and we have directories such as c:\oracle.
While trying to execute one such, we get the following error:
source_file=folder+"\"
^
SyntaxError: Lexical error at line 17, column 23. Encountered: "\r" (13), after : ""
Here folder is my path of c:\oracle and while trying to add file to it like:
source=folder+"\"+src_file
I am not able to do so. Any suggestion on how to solve this issue?
I tried with / but my copy windows calling source in os.command is getting "the syntax is incorrect" and the only way to solve it is to use \ but I am getting the above error in doing so.
Please suggest. Thanks for your help
Thanks.
Short answer:
You need:
source_file = folder + "\\" + src_file
Long answer:
The problem with
source_file = folder + "\" + src_file
is that \ is the escape character. What it's doing in this particular case is escaping the " so that it's treated as a character of the string rather than the string terminator, similar to:
source_file = folder + "X + src_file
which would have the same problem.
In other words, you're trying to construct a string consisting of ", some other text and the end of line (\r, the carriage return character). That's where your error is coming from:
Encountered: "\r" (13)
Paxdiablo is absolutely correct about why \ isn't working for you. However, you could also solve your problem by using os.path.normpath instead of trying to construct the proper platform-specific path characters yourself.
In all programming languages I know of, you can't put a quote inside a string like this: "this is a quote: "." The reason for this is that the first quote opens the string, the second then closes it (!), and then the third one opens another string - with the following two problems:
whatever is between the quotes #2 and #3 is probably not valid code;
the quote #3 is probably not being closed.
There are two common mechanisms of solving this: doubling and escaping. Escaping is far more common, and what it means is you put a special character (usually \) in front of characters that you don't want to be interpreted in their usual value. Thus, "no, *this* is a quote: \"." is a proper string, where the quote #2 is not closing the string - and the character \ does not appear.
However, now you have another problem - how do you actually make the escape character appear in a string? Simple: escape it! "This is an escape: \\!" is how you do it: the backslash #1 is the escape character, and the backslash #2 is the escapee: it will not be interpreted with its usual escape semantics, but as a simple backslash character.
Thus, your line should say this:
source=folder+"\\"+src_file
BTW: upvote for both #paxdiablo (who got in before my diatribe) and #Nick (who has a proper Pythonic way to do what you want to do)