Hi,
I want to change Multi-line string A to another format B, I have the correct PowerShell code,
This key and value are separated by - Key-value pairs are separated by ---
but I want to find the equivalent QM code (loops through in a PowerShell pipeline), I tried many times but it didn't work
Thanks in advance for any advice and help
david
______________________________A______________________________before
A Key
-
Hello 1
World 1
---
B Key
-
Hello 2
World 2
---
C Key
-
Hello 3
World 3
_____________________________B_______________________________after
str A=
A Key
str Av=
Hello 1
World 1
Av.findreplace("[]" "┋")
str B=
B Key
str Bv=
Hello 2
World 2
Bv.findreplace("[]" "┋")
str C=
C Key
str Cv=
Hello 3
World 3
Cv.findreplace("[]" "┋")
str kv=
F
{A}={Av}
{B}={Bv}
{C}={Cv}
DynamicLV(kv)
Powershell Code:
Macro Macro1
I want to change Multi-line string A to another format B, I have the correct PowerShell code,
This key and value are separated by - Key-value pairs are separated by ---
but I want to find the equivalent QM code (loops through in a PowerShell pipeline), I tried many times but it didn't work
Thanks in advance for any advice and help
david
______________________________A______________________________before
A Key
-
Hello 1
World 1
---
B Key
-
Hello 2
World 2
---
C Key
-
Hello 3
World 3
_____________________________B_______________________________after
str A=
A Key
str Av=
Hello 1
World 1
Av.findreplace("[]" "┋")
str B=
B Key
str Bv=
Hello 2
World 2
Bv.findreplace("[]" "┋")
str C=
C Key
str Cv=
Hello 3
World 3
Cv.findreplace("[]" "┋")
str kv=
F
{A}={Av}
{B}={Bv}
{C}={Cv}
DynamicLV(kv)
Powershell Code:
cls
$s = @'
A Key
-
Hello 1
World 1
---
B Key
-
Hello 2
World 2
---
C Key
-
Hello 3
World 3
'@
$ci = 65
$s -split "\r\n---\r\n" | %{
$b = $_ -split "\r\n-\r\n"
$c = [char]$ci
"str $c=`r`n $($b[0])"
"str ${c}v="
$b[1] -split "\r\n" | %{ " $_" }
"${c}v.findreplace(`"[]`" `"┋`")`r`n"
$ci++
}
'str kv='
'F'
65 .. ($ci - 1) | %{ " {$([char]$_)}={$([char]$_)v}" }
'DynamicLV(kv)'
Macro Macro1
out
_s=
;A Key
;-
;Hello 1
;World 1
;---
;B Key
;-
;Hello 2
;
;World 2
;---
;C Key
;-
;Hello 3
;World 3
ARRAY(str) a
tok(_s a -1 "---" 0x2000)
str as=a
str d
int c=65
foreach str'as_ as
,ARRAY(str) b
,tok(as_ b -1 "-" 0x2000)
,d.formata("str %c=[] %s[]str %cv=" c b[0] c)
,ARRAY(str) cc
,tok(b[1] cc -1)
,str ccs=cc
,foreach str'ccs_ ccs
,,d.formata("[]%c.findreplace(''[]'' ''┋'')[]" c b[0] c)
,c+1
;out d
for _i 65 c-1
,d.formata("str kv=[]F[] {%c}={%cv}[]DynamicLV(kv)" _i _i)
;out d