Page 1 of 1

How to extract a string?

Posted: 18 Sep 2019, 14:57
by snowmind
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

Re: How to extract a string?

Posted: 18 Sep 2019, 15:10
by ilhom
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

Re: How to extract a string?

Posted: 18 Sep 2019, 15:12
by snowmind
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 :(

Re: How to extract a string?

Posted: 18 Sep 2019, 15:13
by boiler

Code: Select all

Var=1                                       NULL;;0
RegExMatch(Var, "(\w+)\s*(\w+)", Match)
MsgBox % Match1 "`n" Match2

Re: How to extract a string?

Posted: 18 Sep 2019, 15:15
by boiler
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 "<<<"

Re: How to extract a string?

Posted: 18 Sep 2019, 15:21
by garry
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

Re: How to extract a string?  Topic is solved

Posted: 18 Sep 2019, 21:42
by flyingDman
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)