Noob question Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
trombinator
Posts: 4
Joined: 21 Jan 2020, 10:00

Noob question

22 Jan 2020, 11:10

Hi
I have an output like this:
360 /km2 (980 /sq mi)

I only want to keep 360 how do i do it?

After I have done that how do i numerically sort a dictionary or a list?? I need to sort a bunch of numbers from low to high however i need to associate with each number a city.

Thanks for your help
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Noob question

22 Jan 2020, 12:27

If the result you need is always the first 3 characters of your output, you can simply use:

Code: Select all

output := "360 /km2 (980 /sq mi)"
result := substr(output,1,3)
If the result is the first x characters up to the first space, you can do:

Code: Select all

output := "360 /km2 (980 /sq mi)"
endpos := instr(output, " ") -1
result := substr(output,1,endpos)
You can add multiple results to an array, associating each number with a city. You can sort the array, for example using this good UDF: https://autohotkey.com/board/topic/93570-sortarray/
aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Noob question  Topic is solved

22 Jan 2020, 12:55

here some alternatives

Code: Select all

a := "360 /km2 (980 / sq mi)"
msgbox % "|" Trim(StrSplit(a, "/")[1]) "|" ;with / as seperator, needs Trim to get the number without space at the end
msgbox % "|" StrSplit(a, " ")[1] "|" ;with space as seperator

regexMatch(a, "^(\d{3}).*", MyNumber) ; ^=when number always occurs at the beginning and length of 3 chars
msgbox % "|" MyNumber1 "|"

a := "3603 /km2 (980 / sq mi)"
regexMatch(a, "^(\d{1,4}).*", MyNumber) ;^=when number always occurs at the beginning and length 1 - 4 chars
msgbox % "|" MyNumber1 "|"

;sorting example:
a := "360 /km2 (980 / sq mi)`n310 /km2 (980 / sq mi)`n300 /km2 (980 / sq mi)`n290 /km2 (980 / sq mi)"
Sort, a, N
msgbox % "|" a "|"
trombinator
Posts: 4
Joined: 21 Jan 2020, 10:00

Re: Noob question

23 Jan 2020, 06:01

Thank you very much!!
Regarding the sorting. Why sorting variables won't work?

;sorting example:
Berlin:=55
Paris:=444
Madrid:=3939
a := " Berlin`n Paris`n Madrid "
Sort, a, N
msgbox % "|" a "|"
aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: Noob question

23 Jan 2020, 06:21

Code: Select all

;sorting example:
Berlin:=55
Paris:=444
Madrid:=3939
a := Berlin "`n" Paris "`n" Madrid
Sort, a, N
msgbox % "|" a "|"

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Nerafius, RandomBoy and 192 guests