Reverse the order of a Variable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
magicshow
Posts: 67
Joined: 14 Oct 2022, 11:38

Reverse the order of a Variable

Post by magicshow » 29 Jan 2023, 02:47

I got a Var like this

1
8
0
5
7
2


And i want it to reverse the order like this (num/char doesn't matter)

2
7
5
0
8
1

Researched(sort) but no answer for this , plz help , thks

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Reverse the order of a Variable

Post by Xtra » 29 Jan 2023, 03:45

Try:

Code: Select all

str =
(
1
8
0
5
7
2
)

DllCall("msvcrt.dll\_wcsrev", "UPtr", &str, "CDecl")
MsgBox % str

magicshow
Posts: 67
Joined: 14 Oct 2022, 11:38

Re: Reverse the order of a Variable

Post by magicshow » 29 Jan 2023, 05:37

Xtra wrote:
29 Jan 2023, 03:45
Try:

Code: Select all

str =
(
1
8
0
5
7
2
)

DllCall("msvcrt.dll\_wcsrev", "UPtr", &str, "CDecl")
MsgBox % str
it work, oh yeah , thk :thumbup:

magicshow
Posts: 67
Joined: 14 Oct 2022, 11:38

Re: Reverse the order of a Variable

Post by magicshow » 29 Jan 2023, 08:14

Xtra wrote:
29 Jan 2023, 03:45
Try:

Code: Select all

str =
(
1
8
0
5
7
2
)

DllCall("msvcrt.dll\_wcsrev", "UPtr", &str, "CDecl")
MsgBox % str
My mistake , if the var is more than one char. it will fail...

215
900
155
144
0

0
441 (should be keeping it like 144 and so on)
551 (155)
009 (900)
512 (215)

sofista
Posts: 645
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Reverse the order of a Variable  Topic is solved

Post by sofista » 29 Jan 2023, 11:47

Try this (reverse lines, but not chars):

Code: Select all

str =
(
215
900
155
144
0
)

MsgBox, % ReverseOrderLines(str)

ReverseOrderLines(lines) {
	Loop, Parse, lines, `n, `r
		output := A_LoopField "`n" output
	return output
}

/* Output:
0
144
155
900
215
 */

User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: Reverse the order of a Variable

Post by Chunjee » 29 Jan 2023, 11:49

https://biga-ahk.github.io/biga.ahk/#/?id=reverse

Only works with arrays, so I think for your string situation it might be something like:

Code: Select all

A := new biga() ; requires https://github.com/biga-ahk/biga.ahk

str =
(
1
8
0
5
7
2
)

msgbox, % A.join(A.reverse(strSplit(str, "`n")), "`n")

Post Reply

Return to “Ask for Help (v1)”