Jump to content

Add var to string


Recommended Posts

Hi,

I'm pretty new to Autoit and I have a really simple question.

I have 2 Vars, $var1 and $var2

$var1 = "C:\test\" (used "@WorkingDir")

$var2 = "test.ini"

How can I add $var2 after $var1 ?

I want to have the full path =)

The way I was used to make it doesn't work for AutoIt.

Could you help me ?

Thanks in advance !

Edited by t3mp3st
Link to comment
Share on other sites

The "&" operator joins two strings. e.g. "one" & 10 (equals "one10")

Alternatively you can use the &= assignment, e.g. $var = "one", and then $var &= 10 ($var now equals "one10")

You'd use in this case:

$var1 &= $var2

See the helpfile under language reference - operators.

MDiesel

Link to comment
Share on other sites

This line bothers me a bit depending on your intent

$var1 = "C:\test\" (used "@WorkingDir")

at least the @WorkingDir part does.

You must remember that folder Macros do not contain trailing back slashes and they are not quoted. So if you really meant to use @WorkingDir instead of "C:\Test\" then it should be

$var1 = @WorkingDir & "\"

EDIT. Damn! Read the post post by @mdeisel. Closing brace removed

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This line bothers me a bit depending on your intent

...

$var1 = @WorkingDir & "\")
I'm not sure who to be more worried about, he who actually posts working code (despite explanation being wrong), or he who puts a random closing bracket in the code...

:)

Onto a marginally more serious note, correct use of macros is very important, so you'd better fix it before you come to us saying it doesn't work.

MDiesel

Edited by mdiesel
Link to comment
Share on other sites

I'm not sure who to be more worried about, he who actually posts working code (despite explanation being wrong), or he who puts a random closing bracket in the code...

:)

Onto a marginally more serious note, correct use of macros is very important, so you'd better fix it before you come to us saying it doesn't work.

MDiesel

Thats what I get for only partially editing the paste of someone elses code. I'm ordering a new brain soon.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thats what I get for only partially editing the paste of someone elses code. I'm ordering a new brain soon.

Hopefully won't be worried for much longer then :) I here theyre quite cheap now!

$var1 = @WorkingDir & "\Test.ini"

MsgBox (0, $var1, FileRead ($var1))

Make sure you set @WorkingDir or something, as it is not constant.

MDiesel

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...