How to extract a string? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

How to extract a string?

18 Sep 2019, 14:57

Hiii people

Help me! how can I extract the value "1" and the value "NULL" from this variable:
Var=1 NULL;;0

I try somes scripsts, but nothing Works :-(
I try this

Code: Select all

Var=1                                       NULL;;0
StringSplit, Var_Array, Var, %A_Space%,,
Msgbox %Var_Array1%   ;Here I got the number 1 - Ok
Msgbox %Var_Array2%   ;Nothing happens
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: How to extract a string?

18 Sep 2019, 15:10

Too many spaces it seems.

Code: Select all

Var=1 NULL;;0
StringSplit, Var_Array, Var, %A_Space%,,
Msgbox %Var_Array1%   ;Output 1
Msgbox %Var_Array2%   ;Output NULL;;0
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: How to extract a string?

18 Sep 2019, 15:12

ilhom wrote:
18 Sep 2019, 15:10
Too many spaces it seems.

Code: Select all

Var=1 NULL;;0
StringSplit, Var_Array, Var, %A_Space%,,
Msgbox %Var_Array1%   ;Output 1
Msgbox %Var_Array2%   ;Output NULL;;0
The problem is, when I get this variable, it comes with these spaces :(
User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: How to extract a string?

18 Sep 2019, 15:13

Code: Select all

Var=1                                       NULL;;0
RegExMatch(Var, "(\w+)\s*(\w+)", Match)
MsgBox % Match1 "`n" Match2
User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: How to extract a string?

18 Sep 2019, 15:15

Better yet, to make it clear it doesn't include any spaces in the resulting variables:

Code: Select all

Var=1                                       NULL;;0
RegExMatch(Var, "(\w+)\s*(\w+)", Match)
MsgBox % ">>>" Match1 "<<<`n>>>" Match2 "<<<"
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: How to extract a string?

18 Sep 2019, 15:21

also an example

Code: Select all

Var1=1                                       NULL;A;B
var2:=RegExReplace(var1,"\x20{2,}"," ")   ;- keep only one space
StringSplit,c, Var2, %A_Space%,,
StringSplit,d, c2,`;
msgbox,C1=%c1%`nD1=%d1%`nD2=%d2%`nD3=%d3%
return
or

Code: Select all

Var1=1                                       NULL;A;B
var2:=RegExReplace(var1,"\x20{2,}",";")   ;- replace many spaces with `;
StringSplit,c,var2,`;
msgbox,C1=%c1%`nC2=%c2%`nC3=%c3%`nC4=%c4%
return
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: How to extract a string?  Topic is solved

18 Sep 2019, 21:42

Having a little fun trying to make it a one-liner:

Code: Select all

x=1                                       NULL;;0
msgbox % substr(x,(x ~= "\d"),(x ~= "\s")) "`n" substr(x,y:=(x ~= "[a-zA-Z]"),(x ~= ";")-y)
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen and 346 guests