nill Posted June 22, 2023 Share Posted June 22, 2023 I get the following result in a variable Quote $buf_collect=echo $? 0 ]0;root@ivgl9:~[root@ivgl9 ~]# how do I split this up so I get each string a separate array element using _StringExplode() Link to comment Share on other sites More sharing options...
ioa747 Posted June 22, 2023 Share Posted June 22, 2023 If I get it right #include <String.au3> #include <Array.au3> Local $sTxt = "" $sTxt &= "$buf_collect=echo $?" & @CRLF $sTxt &= "0" & @CRLF $sTxt &= "]0;root@ivgl9:~[root@ivgl9 ~]# " Local $aArray1 = _StringExplode($sTxt, @LF, 0) _ArrayDisplay($aArray1, "_StringExplode") $aArray1 = StringSplit($sTxt, @LF, 1) _ArrayDisplay($aArray1, "StringSplit") nill 1 I know that I know nothing Link to comment Share on other sites More sharing options...
nill Posted June 22, 2023 Author Share Posted June 22, 2023 (edited) in real console (I use VS Code) I have a problem that i got I want to get a zero, which in the screenshot is shown on a separate line (this is the result of the command echo $? in the console) but as you can see a bunch of extra characters are written to the array, although there are none in the autoit console in a regular console (not autoit) this command looks like this Edited June 22, 2023 by nill Link to comment Share on other sites More sharing options...
Andreik Posted June 22, 2023 Share Posted June 22, 2023 (edited) What do you mean by each string? Give us exactly the text that you have in AutoIt variable and what part are you interested to get. Edited June 22, 2023 by Andreik nill 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
nill Posted June 22, 2023 Author Share Posted June 22, 2023 29 minutes ago, Andreik said: What do you mean by each string? Give us exactly the text that you have in AutoIt variable and what part are you interested to get. I mean each line I cant copy exactly what I have in VS Console I showed it on the screenshot above, when I copy I got this Quote echo $? [?2004l 0 [?2004hroot@2aa7e32f703e:/# And I intresting to get line where I have 0 (zero) Link to comment Share on other sites More sharing options...
Solution Andreik Posted June 22, 2023 Solution Share Posted June 22, 2023 #include <Array.au3> $sTxt = 'echo $?' & @CRLF $sTxt &= '[?2004l' & @CRLF $sTxt &= '0' & @CRLF $sTxt &= '[?2004hroot@2aa7e32f703e:/# ' _ArrayDisplay(StringSplit($sTxt, @CRLF, 3)) ConsoleWrite(StringSplit($sTxt, @CRLF, 3)[2] & @CRLF) _ArrayDisplay(StringRegExp($sTxt, '(?m).+', 3)) ConsoleWrite(StringRegExp($sTxt, '(?m).+', 3)[2] & @CRLF) Two ways using native functions. nill 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
nill Posted June 22, 2023 Author Share Posted June 22, 2023 (edited) only StringRegExp($sTxt, '(?m).+', 3) helps, thanks! Edited June 22, 2023 by nill Link to comment Share on other sites More sharing options...
Andreik Posted June 22, 2023 Share Posted June 22, 2023 StringSplit() may fail if LF not CRLF is used for the end of line. StringRegExp() cover both cases. nill 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now