Alternates to quotation marks in Objective C [duplicate] - objective-c

This question already has answers here:
Is it possible to include a quotation mark as part of an nsstring?
(7 answers)
Closed 8 years ago.
I have this line of code in a method:
system("osascript -e 'tell app "System Events" to restart'");
As you can see, I've got two quotation marks, and since these terminal commands have to be so specific, I need to know another way to run a system command from ObjC. I've already tried using '' and the / method but that didn't work out.

You need to "escape" the quote characters to tell the compiler that the should be part of the string rather than delimiters of the string. You say you "tried using … the / method", but you got the wrong character. You escape characters using the backslash, not the forward slash:
-(IBAction)reboot:(id)sender{
system("osascript -e 'tell app \"System Events\" to restart'");
}

Related

How to put a double quote within two double quotes in a batch file and how to escape double quote in VBA script file

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, """", "-"^)
....
)

How to write special characters in vb.net console [duplicate]

This question already has answers here:
How to represent Unicode character in VB.Net String literal?
(7 answers)
Is it possible to get a copyright symbol in C# Console application?
(5 answers)
Closed 6 years ago.
How do i output special characters to the console in visual basic. because simply putting console.writeline("Copyright symbol") outputs a C instead of the symbol. how can i fix this.
You can use the ChrW() function with the Unicode decimal value of the symbol you want to print, for the Copyright symbol it is 169.
console.writeline(ChrW(169))
You can find the Unicode decimal values for other symbols on this website.
The real copyright symbol is a unicode character. Use \u00A9 instead of C to print it out correctly.

Setting A variable with the first word from another variable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to pull the first word from a variable in my batch script to another variable.
ex
if %hello% had "apples are awesome" in it and was pulled and put into %hi%
%hi% would say "apples"
thanks in Advance
This can be done using a for loop:
for /f %%h in ("%hello%") do [command that uses %%h]
The behaviour of "for" in this circumstance is to split its input up into lines (there is only one, assuming there are no newline characters in your input variable), then split each line into tokens on spaces (you can change the delimiter using the "delim=[chars]" option) and pass the first token of each line to the specified command (you can use "tokens=n,n,..." to get at tokens other than the first on the line).
Note that AIUI you can only use a single letter variable name for the variable to receive the word, so you can't use %%hi as you requested.
(This is all untested, as I'm not at a machine running Windows at the moment, but ought to work if I'm reading the documentation correctly.)
set "hi="
for %%h in (%hello%) do if not defined hi set "hi=%%h"
echo %hi%
should work, as would
set "hi="
for %%h in (%hello%) do set "hi=%%h"&goto done
:done
echo %hi%
Note that the set "var=string" syntax ensures that trailing spaces on the line, as left by some editors, are not included in the value assigned.
You don't say clearly whether the value of hello is apples are awesomeor "apples are awesome" - the first is a string of three words with space-separators, the second a single string containing one "word" which contains spaces. I've assumed the former.

Print double quote inside #"" [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to escape double quotes in string?
I need to print a "abc" inside #""
My current string is
[displayLbl setText:#"press stop"];
But i need:
[displayLbl setText:#"press "stop""];
How can i do this?
[displayLbl setText:#"press \"stop\""];
Roland Keesom's answer is of course correct. But you might also consider to use typographic quotation marks, which usually look better:
[displayLbl setText:#"press “stop”"];
(You only have to find them on the keyboard (-: )

why does using "\" shows error in jython

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)