Sign in to follow this  
Followers 0
Raestlin

Parsing A String Variable?

4 posts in this topic

I have code that assigns a DOS output like:

Process Status Time Printer Balance User Address

2716 ACTIVE 15:41:35 0 0 chaney 172.17.100.198

3824 ACTIVE 15:42:27 0 1 administrator 172.17.100.198

*** 2 session(s) ***

to a string variable.

How can I then parse that string of all the above to grab the 2nd and 3rd line

and assign each piece (delimited by space or tab) to an array variable?

So, in other words, I would like the full string above to be processed into:

$line2[0] = 7, which is the number of pieces in line 2.

$line2[1] = "2716"

$line2[2] = "ACTIVE"

$line2[3] = "15:41:35"

...

$line2[7] = "172.17.100.198"

$line3[0] = 7, which is the number of pieces in line 3.

$line3[1] = "3824"

$line3[2] = "ACTIVE"

$line3[3] = "15:42:27"

...

$line2[7] = "172.17.100.198"

Share this post


Link to post
Share on other sites



:think: Didn't your installation come with the help file? :)

Take a look at the String management section. StringSplit and StringRegExp comes to mind :(

Share this post


Link to post
Share on other sites

This should work:

#include <Array.au3>

$str = ClipGet()

$ret = StringSplit($str, @CRLF)
If IsArray($ret) Then
    For $line In $ret
        If $line <> "" Then
            $ret2 = StringSplit($line, " ")
            _ArrayDisplay($ret2, "")
        EndIf
    Next
EndIf

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

This should work:

#include <Array.au3>

$str = ClipGet()

$ret = StringSplit($str, @CRLF)
If IsArray($ret) Then
    For $line In $ret
        If $line <> "" Then
            $ret2 = StringSplit($line, " ")
            _ArrayDisplay($ret2, "")
        EndIf
    Next
EndIf
Thanks Neogia, that code helped me figure out my code perfectly.

Share this post


Link to post
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
Sign in to follow this  
Followers 0