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
Noob question Topic is solved
-
- Posts: 4
- Joined: 21 Jan 2020, 10:00
Re: Noob question
If the result you need is always the first 3 characters of your output, you can simply use:
If the result is the first x characters up to the first space, you can do:
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/
Code: Select all
output := "360 /km2 (980 /sq mi)"
result := substr(output,1,3)
Code: Select all
output := "360 /km2 (980 /sq mi)"
endpos := instr(output, " ") -1
result := substr(output,1,endpos)
Re: Noob question Topic is solved
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 "|"
-
- Posts: 4
- Joined: 21 Jan 2020, 10:00
Re: Noob question
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 "|"
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 "|"
Re: Noob question
Code: Select all
;sorting example:
Berlin:=55
Paris:=444
Madrid:=3939
a := Berlin "`n" Paris "`n" Madrid
Sort, a, N
msgbox % "|" a "|"