Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
equivalent QM code for loops through in a PowerShell pipeline
#1
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: 
 
Code:
Copy      Help
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
Code:
Copy      Help
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


Messages In This Thread
equivalent QM code for loops through in a PowerShell pipeline - by Davider - 11-18-2022, 03:49 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)