StringSplit is a torment for me Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
liij
Posts: 51
Joined: 23 Apr 2016, 13:25

StringSplit is a torment for me

19 Sep 2017, 10:10

Code: Select all

TestString=102/708
; Please make something incredible here with StringSplit, OutputArray, InputVar [, Delimiters, OmitChars] or Array := StrSplit(String [, Delimiters, OmitChars]) 
Variable1:=%OutputArray1% ;Variable1:=102
Variable2:=%OutputArray2%  ;Variable2:=708
I was trying a lot to make it work, please help :monkeysee:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: StringSplit is a torment for me  Topic is solved

19 Sep 2017, 10:14

Code: Select all

TestString := "102/708"
var := StrSplit(TestString,"/")
MsgBox % var[1] "`n" var[2]
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: StringSplit is a torment for me

19 Sep 2017, 10:28

I don't recommend using StringSplit, because it will be removed in AHK v2. I would use StrSplit instead, and would recommend to use BoBo's example above, rather than this example here, which I have provided only to show how it's done:

Code: Select all

q::
TestString=102/708
StringSplit, OutputArray, TestString, /
Variable1:=OutputArray1 ;Variable1:=102
Variable2:=OutputArray2  ;Variable2:=70
MsgBox, % Variable1 " " Variable2

TestString=102/708
StringSplit, OutputArray, TestString, /
Variable1=%OutputArray1% ;Variable1:=102
Variable2=%OutputArray2%  ;Variable2:=70
MsgBox, % Variable1 " " Variable2

TestString := "102/708"
StringSplit, Variable, TestString, /
MsgBox, % Variable1 " " Variable2
return
[2017th post: the current year]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
liij
Posts: 51
Joined: 23 Apr 2016, 13:25

Re: StringSplit is a torment for me

19 Sep 2017, 10:58

jeeswg wrote:I don't recommend using StringSplit, because it will be removed in AHK v2. I would use StrSplit instead, and would recommend to use BoBo's example above, rather than this example here, which I have provided only to show how it's done:

Code: Select all

q::
TestString=102/708
StringSplit, OutputArray, TestString, /
Variable1:=OutputArray1 ;Variable1:=102
Variable2:=OutputArray2  ;Variable2:=70
MsgBox, % Variable1 " " Variable2

TestString=102/708
StringSplit, OutputArray, TestString, /
Variable1=%OutputArray1% ;Variable1:=102
Variable2=%OutputArray2%  ;Variable2:=70
MsgBox, % Variable1 " " Variable2

TestString := "102/708"
StringSplit, Variable, TestString, /
MsgBox, % Variable1 " " Variable2
return
[2017th post: the current year]
My program has over 1800 lines, so I propably will be forced to use current version of ahk
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: StringSplit is a torment for me

19 Sep 2017, 11:12

liij wrote:
jeeswg wrote:I don't recommend using StringSplit, because it will be removed in AHK v2. I would use StrSplit() instead, ...
My program has over 1800 lines, so I propably will be forced to use current version of ahk
The current release offers both options StringSplit vs StrSplit(), you should prefer the second one (function-style) over the historic command style one. So you won't be out of business once AHK 2.0 comes to town :) that's what jeeswg has recommended.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: StringSplit is a torment for me

19 Sep 2017, 11:18

[2017th post: the current year]
StrReplace( :happybday: ,"happypostday") :thumbup:
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: StringSplit is a torment for me

19 Sep 2017, 16:44

If 1800 lines of your script is StringSplit, then I suggest making an array and loop through it, saving results to another array or even overwrite the ongoing one.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], scriptor2016 and 320 guests