StrSplit Strips Decimal Points From Array

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roonyrooxcess
Posts: 61
Joined: 20 Nov 2020, 21:29

StrSplit Strips Decimal Points From Array

25 Nov 2021, 08:15

Hi, im trying to figure out how create an array, but strsplit removes all the decimal points ... no idea why & nothing in google

Thanks!


My Code :

Code: Select all


#SingleInstance, force



Detectxs:=1

Goto m1

m1:
{
;FileRead, Contents, D:\12\Temp\1.txt

Contents = ['2.48800000', '40.10000000']['2.48700000', '300.20000000']['2.48600000', '19.30000000']

StringReplace, Contents, Contents,][,`,, All

;msgbox % Contents
StringReplace, Contents, Contents,[,, All
StringReplace, Contents, Contents,],, All
StringReplace, Contents, Contents,`,, All


Contentsx := StrSplit(Contents,",", "")  ;Splits words by ,

Loop, 20

{
;tooltip % Contents



x++

NewVar%x% := RegExReplace(Contentsx[x], "\D")

tooltip % NewVar%x% " " x


sleep 1000



}
Goto m1
}
Return
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: StrSplit Strips Decimal Points From Array

25 Nov 2021, 09:19

Demonstration:

Code: Select all

Contents   = ['2.48800000', '40.10000000']['2.48700000', '300.20000000']['2.48600000', '19.30000000']
Contentsx := StrSplit(RegExReplace(StrReplace(Contents, "][", ","), "[][ ]"), ",")
For itemNumber, item in Contentsx
 MsgBox,, Item #%itemNumber%, %item%
Your bug: StringReplace, Contents, Contents,`,, All

Problem: By omitting a parameter, you inadvertently decided to replace comma with the word "All".

How to find it: display the values of your variables.

Other things to avoid: deprecated commands such as StringReplace.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], nenyorp, Pianist and 148 guests