Jump to content

How can I use _StringExplode() to split a line break character


Go to solution Solved by Andreik,

Recommended Posts

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

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")

 

I know that I know nothing

Link to comment
Share on other sites

in real console (I use VS Code) I have a problem

that i got 

723a0-clip-57kb.png?nocache=1

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

3d9d8-clip-5kb.png?nocache=1

Edited by nill
Link to comment
Share on other sites

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

  • Solution
#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.

When the words fail... music speaks.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...