Sign in to follow this  
Followers 0
jrchandran

Escaping the " in Send command

7 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

hey SkinnyWhiteGuy,

Thanks for your help. Works like a charm.

ram

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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 :)

Share this post


Link to post
Share on other sites

Hmm, I didn't know about that way of escaping quote characters. Very concise. I like it.

*Puts new trick into bag.*

Thanks enaiman.

Share this post


Link to post
Share on other sites

You're always welcome :)


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 :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0