Posts: 1,083
Threads: 256
Joined: Jul 2022
08-30-2022, 10:21 AM
(This post was last modified: 08-30-2022, 10:30 AM by Davider.)
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
_s=
;abc
;
;abcdef
;
;
;-------------------------------
;ghi
;
;ghij
;
;
;ghijk
;-------------------------------
;lmn
;
;lmno
;
;pq
str s1 s2 s3
Powershell Equivalent codes:
$s = @'
abc
abcdef
-------------------------------
ghi
ghij
ghijk
'@ -split '-------------------------------'
$s1 = $s[0]
$s1
$s2 = $s[1]
$s2
Posts: 1,338
Threads: 61
Joined: Jul 2006
08-30-2022, 01:09 PM
(This post was last modified: 08-30-2022, 01:25 PM by Kevin.)
_s=
;abc
;
;abcdef
;
;
;-------------------------------
;ghi
;
;ghij
;
;
;ghijk
;-------------------------------
;lmn
;
;lmno
;
;pq
str s1 s2 s3
tok _s &s1 -1 "-------------------------------"
out s1
out s2
out s3
Posts: 1,083
Threads: 256
Joined: Jul 2022
Posts: 1,083
Threads: 256
Joined: Jul 2022
08-30-2022, 10:41 PM
(This post was last modified: 08-30-2022, 10:44 PM by Davider.)
@
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
out
_s=
;a
;---------------
;b
str s1 s2
tok _s &s1 2 "---------------"
mes F"s1 = {s1.trim}"
mes F"s2 = {s2.trim}"
Macro Macro4
out
_s=
;---------------
;b
str s1 s2
tok _s &s1 2 "---------------"
mes F"s1 = {s1.trim}"
mes F"s2 = {s2.trim}"
Posts: 1,083
Threads: 256
Joined: Jul 2022
11-21-2022, 12:20 PM
(This post was last modified: 11-21-2022, 12:46 PM by Davider.)
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
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