Convert array to string Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
john_c
Posts: 174
Joined: 05 May 2017, 13:19

Convert array to string

14 Jul 2018, 03:30

Is there way to convert array into string?

Test.ini:

Code: [Select all] [Download] GeSHi © Codebox Plus

[Red]
foo1=bar1
foo2=bar2

[Green]
foo3=bar3
foo4=bar4


Test.ahk:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by john_c on 14 Jul 2018, 04:24, edited 1 time in total.
just me
Posts: 5457
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Convert array to string

14 Jul 2018, 04:02

Code: [Select all] [Download] GeSHi © Codebox Plus

Str := ""
For Index, Value In Array
Str .= Value . "|"
Str := RTrim(Str, "|") ; remove the last pipe (|)
john_c
Posts: 174
Joined: 05 May 2017, 13:19

Re: Convert array to string

14 Jul 2018, 04:21

just me wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

Str := ""
For Index, Value In Array
Str .= Value . "|"
Str := RTrim(Str, "|") ; remove the last pipe (|)


Thank you, but I don't sure it works for me. I tried to add "MsgBox, %Str%" at the bottom and it doesn't show me anything. AHK version 1.1.27.07. Does it work for you?
just me
Posts: 5457
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Convert array to string  Topic is solved

14 Jul 2018, 04:44

Code: [Select all] [Download] GeSHi © Codebox Plus

#NoEnv
Array := []
Array.Push("Red")
Array.Push("Green")

Str := ""
For Index, Value In Array
Str .= "|" . Value
Str := LTrim(Str, "|") ; Remove leading pipes (|)
MsgBox, %Str%

?
john_c
Posts: 174
Joined: 05 May 2017, 13:19

Re: Convert array to string

14 Jul 2018, 05:50

just me wrote:?


Yes, it works in your example, thanks. Now I understand that there is an error in my initial script and will try to find it
john_c
Posts: 174
Joined: 05 May 2017, 13:19

Re: Convert array to string

14 Jul 2018, 06:20

just me wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

#NoEnv
Array := []
Array.Push("Red")
Array.Push("Green")


It's a bit offtopic here, but could you please elaborate the difference between "Array.Push" and "Array.Insert"? They seems to work identically in provided example.
just me
Posts: 5457
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Convert array to string

14 Jul 2018, 07:07

Insert wrote:Deprecated: Insert is not recommended for use in new scripts. Use InsertAt, Push, ObjRawSet or a simple assignment instead.

BTW: A_LoopReadLine is only defined within a file-reading loop.
john_c
Posts: 174
Joined: 05 May 2017, 13:19

Re: Convert array to string

14 Jul 2018, 08:42

just me wrote:...


Understand, thanks!

Return to “Ask For Help”

Who is online

Users browsing this forum: eqv, lluke, Scoox, ToKa, Wickster and 71 guests