I am attempting to use a Local variable in a DirCopy command but when I insert the $Variable into the C:\Users\store$Variable\Desktop path it attempts to read the path literally instead of using the $Variable.
The objective is to create a prompt for the Store number and insert that number into a bunch of DirCopy lines to ensure we get the profiles that contain only that number. The issue is that the profiles are one word, ex. store123, reciever123.
This is what I put together so far but I can't get it to take the variable in this way.
Local $STORE = InputBox ( "Store Number" , "What Store is This?" )
DirCopy ( "\\192.168.1.3\C$\Documents and Settings\store$STORE\Desktop" , "C:\Users\Store$STORE\desktop" )
DirCopy ( "\\192.168.1.3\c$\Documents and Settings\Profile$STORE\Desktop" , "C:\Users\Profile$STORE\Desktop")
Is there a formatting issue? or is this not possible in AutoIT?
Method 1: Concatenation
In order to use Variables inside strings, you need to concatenate them, by using the & operator:
$nVar = 42
$sStr = "Hello, " & $nVar & "World!"
; $sStr will now hold: "Hello, 42World!"
Method 2: Expansion
However, there is a Opt() flag ExpandVarStrings that enables inline variable use:
Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
$nVar = 42
$sStr = "Hello, $nVar$World!"
; $sStr contains: "Hello, 42World!"
Related
I have a query say :
"select .... " > $my_result
This will store in the my_result but as a file. How to store in a my_result variable itself if that query gives only one row without creating a file.
Simplest way would be:
my_result=$(select ...)
And when you want to print it:
echo $my_result
I Googled it but i'm not able to find a GOOD solution.
My goal is to put a string which is composed of 6 lines in one string, and only one, in a variable.
For example, my string can look like :
a
b
c
and I want it to be in one string. I tried the thing witch ^, or with ECHO " " but it doesn't work : the cmd put an error "not recognized as an internal command" (and it's normal, it's just some sentences, not batch commands!)
Thanks, Clément
Not so simple but possible :
#echo off
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
REM Example Usage:
setlocal enableDelayedExpansion
set "string_with_new_lines=a!nl!b!nl!c"
echo %string_with_new_lines%
Aacini has a simpler solution for this using empty variable,but I'm struggle to find the link.
Following the comments on the post answer of #npocmaka
It's currently in Python, so the """ thing works.
requete = """
PREFIX resources: <http://www.fluidops.com/resource/>
SELECT DISTINCT ?id ?marque ?modele WHERE {
?voiture resources:uid ?id.
?voiture resources:bpqmqvc ?marque. #myComment
?voiture resources:bpqmodvc ?modele
}
"""
I have an IDL function that takes in up to 4 data variables: data1, data2, data3 and data4. I want to be able to access the level=-1 scope of these variables in a loop using a string construct for the data variable name, so I can document the name of the original data that was passed to the function in an efficient manner.
Here's a simplified version of the function, showing only pertinent parts.
Function funcData, dat1, dat2, dat3, dat4,
n=1
txt = "Data "
;Check that data variable n was passed.
WHILE N_ELEMENTS(scope_varfetch("dat"+strtrim(n+1,1), level=0, /enter)) $
NE 0 DO BEGIN
dat = scope_varfetch("dat"+strtrim(n,1), level=0, /enter) ; get data
txt=txt + scope_varname("dat"+ strtrim(n,1), level=-1) +", " ; data names
n+=1 ; update n
ENDWHILE
END
The problem is that scope_varfetch handles the concatenated string construct "dat"+strtrim(n,1) and returns the appropriate data set, but scope_varname does not, returning a blank.
Does anyone know why this is happening?
Is there another way I can do this (short of brute force, case format)?
I have tried to search for an answer on-line, but have not been able to find anything about using string constructs in the IDL scope functions.
A Facebook contact provided this solution:
result=execute('sv=scope_varname(dat'+ strtrim(n,1)+', level=-1)')
txt=txt + sv + ", "
Works perfectly.
scope_varname expects a variable as its parameter, so you need an extra call to scope_varfetch when using it:
txt=txt + scope_varname((scope_varfetch("dat"+ strtrim(n,1))), level=-1) +", " ; data names
I'm still getting used to the concept of string patterns, and I've run into an issue regarding them. I'm trying to create a simple program that searches a string of text, for certain characters encapsulated in whatever the brackets may be. Here's an example:
local str = "Hello <<world>>, my <<name>> is <<John>>"
-- Match patterns with << ... >>
for noun in str:gmatch("<<.->>") do
print(noun)
end
This program will search through the string, matching everything that starts with << and ends with >>, and everything in between. Good, that's what I want. However, let's say I wanted a different pattern that only got text between one of those tags instead of two (< and > instead of << and >>). This is where I run into a problem:
-- Allow easy customization control over brackets
local matchNouns = {"<<", ">>"}
local matchOther = {"<", ">"}
local str = "<Hello> <<world>>, <my> <<name>> <is> <<John>>"
local function printOtherMatches(str)
-- Get opening and closing brackets
local open, close = unpack(matchOther)
-- Concatenate opening and closing brackets with
-- pattern for finding all characters in between them
for other in str:gmatch(open .. ".-" .. close) do
print(other)
end
end
printOtherMatches(str)
The program above will print everything between < and > (the matchOther elements), however it also prints text captured with << and >> as well. I only want the iterator to return patterns that explicitly match the opening and closing tags. So the output from above should print:
<Hello>
<my>
<is>
Instead of:
<Hello>
<<world>>
<my>
<<name>>
<is>
<<John>>
Basically, just like with markdown how you can use * and ** for different formats, I'd like to create a string pattern for that in Lua. This was my attempt of emulating that kind of pattern sequence. If anyone has any ideas, or insight on how I could achieve this, I'd really appreciate it!
-- Allow easy customization control over brackets
local matchNouns = {"<<", ">>"}
local matchOther = {"<", ">"}
local delimiter_symbols = "<>" -- Gather all the symbols from all possible delimiters above
local function printMatches(str, match_open_close)
-- Get opening and closing brackets
local open, close = unpack(match_open_close)
-- Concatenate opening and closing brackets with
-- pattern for finding all characters in between them
for other in str:gmatch(
"%f["..delimiter_symbols:gsub("%p", "%%%0").."]"
..open:gsub("%p", "%%%0")
.."%f[^"..delimiter_symbols:gsub("%p", "%%%0").."]"
.."(.-)"
.."%f["..delimiter_symbols:gsub("%p", "%%%0").."]"
..close:gsub("%p", "%%%0")
.."%f[^"..delimiter_symbols:gsub("%p", "%%%0").."]"
) do
print(other)
end
end
local str = "<Hello> <<world>>, <my> <<name>> <is> <<John>>"
printMatches(str, matchOther)
Here's one possibility:
local s = '<Hello> <<world>>, <my> <<name>> <is> <<John>>'
for s in s:gmatch '%b<>' do
if not s:sub(2,-2):match '%b<>' then print(s) end
end
I have created a structure containing a few different fields. The fields contain data from a number of different subjects/participants.
At the beginning of the script I prompt the user to enter the "Subject number" like so:
prompt='Enter the subject number in the format SUB_n: ';
SUB=input(prompt,'s');
Example SUB_34 for the 34th subject.
I want to then name my structure such that it contains this string... i.e. I want the name of my structure to be SUB_34, e.g. SUB_34.field1. But I don't know how to do this.
I know that you can assign strings to a specific field name for example for structure S if I want field1 to be called z then
S=struct;
field1='z';
S.(field1);
works but it does not work for the structure name.
Can anyone help?
Thanks
Rather than creating structures named SUB_34 I would strongly recommend just using an array of structures instead and having the user simply input the subject number.
number = input('Subject Number')
S(number) = data_struct
Then you could simply find it again using:
subject = S(number);
If you really insist on it, you could use the method proposed in the comment by #Sembei using eval to get the struct. You really should not do this though
S = eval([SUB, ';']);
Or to set the structure
eval([SUB, ' = mydata;']);
One (of many) reasons not to do this is that I could enter the following at your prompt:
>> prompt = 'Enter the subject number in the format SUB_n: ';
>> SUB = input(prompt, 's');
>> eval([SUB, ' = mydata;']);
And I enter:
clear all; SUB_34
This would have the unforeseen consequence that it would remove all of your data since eval evaluates the input string as a command. Using eval on user input assumes that the user is never going to ever write something malformed or malicious, accidentally or otherwise.