Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Access the values of the hash table
#1
Hi,

I want to store multiple lines of text in the key of the hash table, after which I can access the value through the key
Below is an example of Powershell code

In QM, how to implement similar functions?  Or, how to create a function with similar functionality?

Thanks in advance for any advice and help
david

Powershell Code:
Code:
Copy      Help
$s = @'
mes1 :sub.Sub1
mes2 :sub.Sub2

#sub Sub1 m
_s="hello 1"
mes _s

#sub Sub2 m
_s="hello 2"
mes _s
'@
$hash = @{ }
foreach ($m in [regex]::Matches($s, '(?m)^#sub Sub(\d+) m(?:(?!^#sub Sub\d+ m)[\s\S])+'))
{
    $key = $m.Groups[1].Value
    $value = $m.Groups[0].Value.Trim()
    if (!$hash.Contains($key))
    {
        $hash.Add($key, $value)
    }
}
$hash['1']
#2
I thought of the following method, but the final replacement result is wrong, why?

Macro Macro5
Code:
Copy      Help
out
_s=
;mes1 :sub.Sub1
;mes2 :sub.Sub2
;
;#sub Sub1 m
;_s="hello 1"
;mes _s
;
;#sub Sub2 m
;_s="hello 2"
;mes _s
ARRAY(str) as
findrx(_s "(?m)^#sub Sub(\d+) m(?:(?!^#sub Sub\d+ m)[\s\S])+" 0 4 as)

str k v kv
for _i 0 as.len
,k=as[1 _i]
,v=as[0 _i].trim
,v.findreplace("[]" "┃")
,kv.formata("%s=%s[]" k v)
out kv

IStringMap m._create
m.AddList(kv "=")

v=m.Get("1")
if(v)
,out v ;;The output is correct
,out v.findreplace("┃" "[]") ;;The output is wrong, why?
else
,out "not found"
#3
change 
out v.findreplace("┃" "[]")

to
Code:
Copy      Help
,v.findreplace("┃" "[]")
,out v
#4
@Kevin
thank you so much


Forum Jump:


Users browsing this thread: 1 Guest(s)