Sign in to follow this  
Followers 0
Othni

Double Quotes

20 posts in this topic

Being double quotes a special characters, how can I specify a double quote in a string?

Share this post


Link to post
Share on other sites



Like this: $string = ""Hello World!""


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Hi,

' " ' .... square the double quotes between single ones

Ex :

$String = "She's a " & '"' & "special" & '"' & " girl..."

Msgbox(0,"Test",$String)


FreeRiderHonour & Fidelity

Share this post


Link to post
Share on other sites

$string = "Or you double your ""quote"" characters within the string"

Share this post


Link to post
Share on other sites

Like this: $string = ""Hello World!""

You missed two extra double quotes on the outside. This is uglier than using single quotes.

$string = """Hello World!"""

Share this post


Link to post
Share on other sites

There are two ways of specifying quotes inside a string.

  • Surround with single quotes
  • Double up the double quotes

Surround with single quotes

$var = 'Single quotes surrounding "double quotes".'oÝ÷ Ù°è¹¹^ºh¹¹^ªê-zÏÛjëh×6$var = "Doubled up ""quotes""."

I hope this helps.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

You missed two extra double quotes on the outside. This is uglier than using single quotes.

:) I feel so ashamed :)

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

How to mess up a wet dream -

;Trust me, there are only two reasonable ways you would ever normally specify a double-quote in a string
;And the second choice is the only choice 9 times out of ten:
MsgBox(0,"", Chr(34) & "Hello World!" & Chr(34))
MsgBox(0,"", '"Hello World!"')

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

Wow, a lot of replies in a short time.

Thank you guys.

I can not make it work. This is what I am trying to achieve.

FileCopy ("oldfolder\oldname.pdf", $CmdLine[1] & "\newname.pdf" )

Basically I am having problems copying to destinations with spaces.

The $CmdLine[1] is a parameter passed from another script that prompted the user to select a folder destination.

So, for example, the parameter could be converted to C:\Document and Settings\User\My Documents\My New PDFs

I am thinking that I need to so specify some double quotes to the left of $CmdLine[1] and then at the right end of the script. Right?

I have tried your suggestions, but can not make it work. I will keep trying to see if missed something.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

If you are actually using the FileCopy command from AutoIt, you should not embed double-quotes for the parameters, but you need the flag 8 if the destination directory structure does not exist:

$DestDir = StringStripWS($CmdLine[1],3)
If StringRight($DestDir,1) = "\" Then
    $DestDir = StringTrimRight($DestDir,1)
EndIf
FileCopy ("oldfolder\oldname.pdf", $DestDir & "\newname.pdf", 8)

I don't know what the general rules are for this, except that for the Run, RunWait, ShellExecute, and ShellExecuteWait commands, embedding double-quotes is necessary if there is a space in the file path; for native AutoIt functions elsewise, don't ; if you are using a UDF and the script isn't working, try embedding.

Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Well, right now it does not work only when the $CmdLine[1] value contains any spaces.

If the $CmdLine[1] paramter is C:\folder, everything works.

If the $CmdLine[1] paramter is C:\This is the folder , does not work.

Edit: Sorry I am including the Flag 8. But for simplicity, I omitted that from the example.

Edited by Othni

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

There might be exceptions to every rule then - for your edition of Windows try this:

$DestDir = StringStripWS($CmdLine[1],3)
If StringRight($DestDir,1) = "\" Then
    $DestDir = StringTrimRight($DestDir,1)
EndIf
$Dest = $DestDir & '\newname.pdf'
If StringInStr($Dest, " ") Then
    $Dest = '"' & $Dest & '"'
EndIf
FileCopy ("oldfolder\oldname.pdf", $Dest , 8)

Here is another option:

$Dest = $DestDir & '\newname.pdf'
If StringInStr($Dest, " ") Then
    $Dest = '"' & $Dest & '"'
EndIf
RunWait("Copy C:\oldfolder\oldname.pdf " & $Dest)
Edited by Squirrely1

Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites

Ok, thank you, I will test this tomorrow.

But there is a limitation with the Copy command, it requires the folder structure to be created.

And, although I did not mentioned it before, the destination also need to create a folder in addition to rename the source file.

More like this...

FileCopy ("oldfolder\oldname.pdf", $CmdLine[1] & "\newfolder\newname.pdf" )

Notice the newfolder at the right of the function.

I had made it work this morning with Xcopy and specifying and input file to answer automatically the prompts, BUT, it was much slower.

The FileCopy from AutoIt and the Copy command (from the DOS prompt) are much faster.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Wow, a lot of replies in a short time.

Thank you guys.

I can not make it work. This is what I am trying to achieve.

FileCopy ("oldfolder\oldname.pdf", $CmdLine[1] & "\newname.pdf" )

Basically I am having problems copying to destinations with spaces.

This should solve your problem

FileCopy ("oldfolder\oldname.pdf", & '"' & $CmdLine[1] & "\newname.pdf" & '"' )
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

When you are looking for the output directory to be created when not existing then have a look at the 3rd parameter of filecopy() in the helpfile.

:)

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This should solve your problem

FileCopy ("oldfolder\oldname.pdf", & '"' & $CmdLine[1] & "\newname.pdf" & '"' )

Thank you but it just does not work. Other did mentioned about enclosing double quotes with single quotes and also doubling up the double quotes. At least it does not work with FileCopy for some reason.

Share this post


Link to post
Share on other sites

When you are looking for the output directory to be created when not existing then have a look at the 3rd parameter of filecopy() in the helpfile.

:)

Thank you, I am using the third parameter. I only omitted it form my original post for simplicity. I clarified it further down.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

...

Basically I am having problems copying to destinations with spaces.

...

Therein lies part of the problem. You're only referencing $CmdLine[1]. If you're using a sample scenario of a new destination folder of C:\Test Folder being passed via the command line to your executable, then the array $CmdLine would have the following values:

$CmdLine[0] = "2"

$CmdLine[1] = "C:\Test"

$CmdLine[0] = "Folder"

$CmdLine[0] shows the number of parameters passed, and the subsequent parameters are the detected parameters, separated by spaces. If, however, you used $CmdLineRaw instead, then you would have a return as such:

$CmdLineRaw = "C:\Test Folder"

And, although I did not mentioned it before, the destination also need to create a folder in addition to rename the source file.

More like this...

FileCopy ("oldfolder\oldname.pdf", $CmdLine[1] & "\newfolder\newname.pdf" )

Notice the newfolder at the right of the function.

Using the notes above, try:

FileCopy ("oldfolder\oldname.pdf", $CmdLineRaw & "\newfolder\newname.pdf",8 )

***Edit***Extra note: depending upon how you're having the parameter passed from the folder selection process, you may or may not have to factor in dealing with a trailing slash("\")

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

This does work with

With $CmdLine[1] = "C:\Data1 Data2"

The quote are required to successfully pass the new folder but must be removed for use in FileCopy.

StringReplace is used to strip the quotes from $CmdLine[1]

$Result = FileCopy ("C:\Test.txt", StringReplace($CmdLine[1],'"',"") & "\Test.txt" , 9)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

This does work with

With $CmdLine[1] = "C:\Data1 Data2"

The quote are required to successfully pass the new folder but must be removed for use in FileCopy.

StringReplace is used to strip the quotes from $CmdLine[1]

$Result = FileCopy ("C:\Test.txt", StringReplace($CmdLine[1],'"',"") & "\Test.txt" , 9)

Thank you a lot! It worked!

First I made sure the command line parameter was being enclosed in double quotes upon execution of the script. Then I used StringReplace to remove the quotes within FileCopy and it worked.

Thank you all for you input.

This forum is great!

Edited by Othni

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