Posts: 1,049
Threads: 249
Joined: Jul 2022
11-08-2022, 12:17 AM
(This post was last modified: 11-08-2022, 12:17 AM by Davider.)
Hi,
In the following code, the key-values are multi-line strings, how to output them? only output one line?
Is there any other way to achieve this?
Thanks in advance for any advice and help
david
Macro
Macro17
out
str A="1 key"
str Av=
;1 hello
;1 world
str B="2 key"
str Bv=
;2 hello
;2 world
str C="3 key"
str Cv=
;3 hello
;3 world
str kv=
F
;{A}={Av}
;{B}={Bv}
;{C}={Cv}
IStringMap m._create
m.AddList(kv "=")
str v=m.Get("1 key")
if(v)
,out v
else
,out "not found"
Posts: 1,049
Threads: 249
Joined: Jul 2022
11-08-2022, 02:19 AM
(This post was last modified: 11-08-2022, 02:21 AM by Davider.)
I thought of the following method, which is a bit tedious
How to get the defined variable name, automatically generate the following code
--------------------------------------------------------------------------------------------------
Av.replacerx("[]" "┃")
Bv.replacerx("[]" "┃")
Cv.replacerx("[]" "┃")
str kv=
F
{A}={Av}
{B}={Bv}
{C}={Cv}
Macro
Macro18
out
str A="1 key"
str Av=
;1 hello
;1 world
str B="2 key"
str Bv=
;2 hello
;2 world
str C="3 key"
str Cv=
;3 hello
;3 world
Av.replacerx("[]" "┃")
Bv.replacerx("[]" "┃")
Cv.replacerx("[]" "┃")
str kv=
F
;{A}={Av}
;{B}={Bv}
;{C}={Cv}
IStringMap m._create
m.AddList(kv "=")
str v=m.Get("1 key")
if(v)
,v.replacerx("┃" "[]")
,out v
else
,out "not found"
Posts: 1,338
Threads: 61
Joined: Jul 2006
11-08-2022, 02:43 AM
(This post was last modified: 11-08-2022, 03:06 AM by Kevin.)
need to use csv format for multiline strings and csv as separator
out
str A="1 key"
str Av=
;"hello
;world"
str B="2 key"
str Bv=
;"hello
;world"
str C="3 key"
str Cv=
;"hello
;world"
str kv=
F
;{A},{Av}
;{B},{Bv}
;{C},{Cv}
IStringMap m._create
m.AddList(kv "csv")
str v=m.Get("1 key")
if(v)
,out v
else
,out "not found"
Posts: 1,049
Threads: 249
Joined: Jul 2022
11-08-2022, 03:33 AM
(This post was last modified: 11-08-2022, 03:51 AM by Davider.)
I want to output the original multi-line string
For example
str Av=
1 hello
1 world
In the following way, there will be an escape problem, e.g:
str Av=
1 hello"
1 world"
The #2 method is stable
Macro
Macro20
out
str A="1 key"
str Av=
;1 hello
;1 world
str B="2 key"
str Bv=
;2 hello
;2 world
str C="3 key"
str Cv=
;3 hello
;3 world
str kv=
F
;{A},"{Av}"
;{B},"{Bv}"
;{C},"{Cv}"
IStringMap m._create
m.AddList(kv "csv")
str v=m.Get("1 key")
if(v)
,out v
else
,out "not found"
Posts: 1,338
Threads: 61
Joined: Jul 2006
11-08-2022, 04:06 AM
(This post was last modified: 11-08-2022, 04:06 AM by Kevin.)
in first method your format is incorrect
should be
str Av=
"1 hello
1 world"
str B="2 key"
str Bv=
"2 hello
2 world"
str C="3 key"
str Cv=
"3 hello
3 world"
second method will work as well