Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple lines of text are split and assigned to multiple variables
#1
Hi,

I want to split multiple lines of text and assign values to multiple variables
Blank lines inside are to be reserved

The symbol that splits the row is -------------------------------

The first part is assigned to the variable s1
The second part is assigned to the variable s2
The third part assigns the value to the variable s3

Thanks in advance for any advice and help
david

Macro Macro2
Code:
Copy      Help
_s=
;abc
;
;abcdef
;
;
;-------------------------------
;ghi
;
;ghij
;
;
;ghijk
;-------------------------------
;lmn
;
;lmno
;
;pq

str s1 s2 s3

Powershell Equivalent codes:
 
Code:
Copy      Help
 
$s = @'
abc

abcdef


-------------------------------
ghi

ghij


ghijk
'@ -split '-------------------------------'

$s1 = $s[0]
$s1

$s2 = $s[1]
$s2
#2
Code:
Copy      Help
_s=
;abc
;
;abcdef
;
;
;-------------------------------
;ghi
;
;ghij
;
;
;ghijk
;-------------------------------
;lmn
;
;lmno
;
;pq

str s1 s2 s3
tok _s &s1 -1 "-------------------------------"
out s1
out s2
out s3
#3
worked well, thank you
#4
@Kevin

How to
Let s1 always save the text above the separator line
Let s2 always save the text below the separator line

In Macro4, it is the opposite, 
I need the results
s1=
s2=b

Macro Macro3
Code:
Copy      Help
out
_s=
;a
;---------------
;b

str s1 s2
tok _s &s1 2 "---------------"
mes F"s1 = {s1.trim}" 
mes F"s2 = {s2.trim}"

Macro Macro4
Code:
Copy      Help
out
_s=
;---------------
;b

str s1 s2
tok _s &s1 2 "---------------"
mes F"s1 = {s1.trim}" 
mes F"s2 = {s2.trim}"
#5
This looks like a bug 

The result should be:
Key 1|-|Hello 1|World 1|

My understanding is wrong, I just found the help documentation:
Note that delim is not a delimiter string. It is a set of possible delimiter characters

Macro Macro6
Code:
Copy      Help
out
_s=
;Key 1
;-
;Hello 1
;World 1
;---
;Key 2
;-
;Hello 2
;
;World 2
;---
;Key 3
;-
;Hello 3
;World 3

_s.findreplace("[]" "|")
out _s
ARRAY(str) a
tok(_s a -1 "---")
out a[0]

It would be nice to have a split function like #1 with the same functionality as PowerShell


Forum Jump:


Users browsing this thread: 1 Guest(s)