Posts: 763
Threads: 261
Joined: Jul 2012
Hello,
beginner needing help:
1)
What is the best way to retrieve everthing beneath "[config2]" until the next [...], I want to retrieve "cde" , "fgh" and "ijk"
[config1]
abc
[config2]
cde
fgh
ijk
[config3]
etc...
2)
How can I put a variable within a findrx regex pattern:
findrx(lines "^\[config2](?:\r?\n(?:[^[\r\n].*)?)*" 0 8 x)
I want the string "config2" be replaced by a variable for exmple "var_config"
findrx(lines "^\[
var_config](?:\r?\n(?:[^[\r\n].*)?)*" 0 8 x)
I tried {var_config}
I tried:
RunTextAsFunction2
But I keep against the double quotes problem
str result="findrx(lines "^\[config2](?:\r?\n(?:[^[\r\n].*)?)*" 0 8 x)"
I also tried to replace the inner pair of double quotes with double single quotes like this: '' ... regex...''
thanks!
Posts: 12,028
Threads: 139
Joined: Dec 2002
Macro
Macro1792
out
str lines=
;[config1]
;abc
;
;[config2]
;cde
;fgh
;ijk
;
;[config3]
;etc...
str var_config="config2"
str x
if findrx(lines F"(?s)^\Q[{var_config}]\E(.+?)(?:^\[|\z)" 0 8 x 1)>=0
,x.trim
,out x
else out "not found"
Also can be used API function GetPrivateProfileSection.
To add variables to a string, there are 2 ways:
1. Put F before the string, and insert variables enclosed in { }. Example: F"string {variable} string"
2. Use function str.format.
When using in regular expression, enclose variables in \Q \E. Then variable text is interpreted as simple text, not as regular expression.
Posts: 763
Threads: 261
Joined: Jul 2012
thanks man!
you have no idea how relieved I am seeing the correct result in the output window!!
- Did you actually build this powerhouse tool yourself? And is Quick Macros programmed/build using the Quick Macro scripting language itself?
- On what language is the Quick Macro scripting language based? (or this language build from the ground up?)
Posts: 12,028
Threads: 139
Joined: Dec 2002
Quick Macros is programmed using C++ (>50%) and QM language (<50%). Most of code is mine, but parts are from various libraries, for example PCRE for regular expressions, scintilla for editor, mailbee for email.
The language is not based on other languages. Something is similar to C++, something to some other languages.
Posts: 763
Threads: 261
Joined: Jul 2012
Thanks for your help and info!!
Posts: 858
Threads: 196
Joined: Apr 2005
Can you add the example using GetPrivateProfileSection?
Posts: 12,028
Threads: 139
Joined: Dec 2002
Macro
Macro1793
out
;---------------
;create ini file for testing
str lines=
;[config1]
;abc
;
;[config2]
;cde=1
;fgh=2
;ijk=3
;
;[config3]
;etc...
str iniFile.expandpath("$temp$\qm48825.ini")
lines.setfile(iniFile)
;---------------
str var_config="config2"
str x
int nSize=100*1024; x.all(nSize)
x.fix(GetPrivateProfileSection(var_config x nSize iniFile))
if x.len
,;GetPrivateProfileSection returns multistring; show each string
,lpstr s=x
,rep
,,if(!s[0]) break
,,out s
,,s+len(s)+1
else out "not found"
;this is not perfect code. 1. Need to ensure that nSize is big enough; 2. Need to use Unicode function version to support Unicode in ini file path.
Posts: 858
Threads: 196
Joined: Apr 2005