Jump to content

Escaping the " in Send command


Recommended Posts

Hi,

How do i escape using the " inside a send command. Lets say i want to send a line which includes a word that needs to be pre-fixed and suffixed by ", it gives me an error. How do i escape this. Please help me here.

eg : Send ("The name of this country is "USA" and i love to live here")

In the above sentence i want "USA" to be printed as well, it gives an error as it thinks The name of this country is to be one part of the line and and i love to live here to be the other part.

thanks,

ram

Link to comment
Share on other sites

send('this is a " quoteed word"')

single quotes for the win (next time, please read the help file)

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

Well, the reason it things that the line is broken up, is by using the same quotes in the string as you tried to use around the string, AutoIt thinks the String is stopping before you want it to. Course, other languages do this, too, not just AutoIt.

There are 2 ways to usually solve this. If your string is like yours, where what you want to send only contains one type of quotation marks in it, change the surrounding marks to the opposite one. In your case, since you need " in the string, put ' around the string.

Now, if you need both kinds of quotes in your string, you'd need to "escape" those characters. In AutoIt, there's no easy to do it as in other languages, so you can use the above method, putting strings together using & when you need to swap, or use the Chr() function (still using &'s) to insert the other character when needed.

For example:

; Simple Fix
Send('The name of the country is "USA" and i love to live here')

; More Complex Fix
Send("The name of the country is " & '"USA"' & " and i love to live here")

; Final Complexity Fix
Send("The name of the country is " & Chr(<insert number of " character>) & "USA" & Chr(<same number as before>) & " and i love to live here")

This works the same with just assigning values to strings, as it does with strings as arguments to functions.

Link to comment
Share on other sites

To say it shorter:

If you want to send a quoted word "blahblah" always use double quotes and it will work ""blahblah""

Your example:

Send ("The name of this country is ""USA"" and i love to live here")

The other solutions works very well too. Personally I use the above style; this way I don't need to worry about mixing things.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...