Jump to content

Recommended Posts

Posted

How can I isolate and capture a specific string from a terminal emulator? I got as far as capturing everything in the current window to the clipboard but that's about it. After capturing everything to the clipboard, I tried to...

$text = clipGet
$newstring = StringSplit($text, " ") ; spaces are the delimiter

...but this does not do what I thought it would. Apparently one must enclose "text in double quotes like this" as argument 1 to StringSplit().

Posted

You mean:

$text = ClipGet()

WBD

That was a typo in the posting, not in my actual script. I'm able to successfully capture the contents from the clipboard. I just don't know how to parse $text and extract a specific string.

Thanks!

Posted (edited)

That was a typo in the posting, not in my actual script. I'm able to successfully capture the contents from the clipboard. I just don't know how to parse $text and extract a specific string.

Thanks!

What does $text look like and what are you trying to capture? StringSplit will split a string by the delimiter into an array. For example:

$var = "How now brown cow"
$text = StringSplit($var, " ")

Would return

$text[0] = 4

$text[1] = "How"

$text[2] = "Now"

$text[3] = "Brown"

$text[4] = "Cow"

Where the first position of the array (zero) would be the number of split items (4 in this case for 4 words). You could also use functions like StringInStr, StringLeft, StringMid, and StringRight to get parts of $text if you know what you're looking for.

Edited by ChrisFromBoston
Posted

This is what gets stored in $text. All I really need to capture is the Order No: 24793485. I can't use AutoIt's window info feature because the text is in a "terminal" not a window.

/dev/pts/12: Connected to Virtual Machine 'pick0:LINUX'.
TEST CORP SALES (DETAIL)  Primary Whse: 6   123456      08:22:10 05/01/09
Trans Cd: A (A,B,D,F,I,L,M,S,/)   Order No: 24793485   Customer No: 000130522
Order for: TEST MXPQFG5F3C            Placed By: WJB
Line PB Price... Catalog No Catalog Color. * Description........... Amount....
     W
Weight:     1 ================== Pieces:        1 ====== Amount:      11.99
   1  1 11.99 K420     Athletic Gold    PA Pique Sport Shirt        11.99
     6                                    M:    1
Posted

This is what gets stored in $text. All I really need to capture is the Order No: 24793485. I can't use AutoIt's window info feature because the text is in a "terminal" not a window.

/dev/pts/12: Connected to Virtual Machine 'pick0:LINUX'.
TEST CORP SALES (DETAIL)  Primary Whse: 6   123456      08:22:10 05/01/09
Trans Cd: A (A,B,D,F,I,L,M,S,/)   Order No: 24793485   Customer No: 000130522
Order for: TEST MXPQFG5F3C            Placed By: WJB
Line PB Price... Catalog No Catalog Color. * Description........... Amount....
     W
Weight:     1 ================== Pieces:        1 ====== Amount:      11.99
   1  1 11.99 K420     Athletic Gold    PA Pique Sport Shirt        11.99
     6                                    M:    1

will this work for you?

$string = "Trans Cd: A (A,B,D,F,I,L,M,S,/)   Order No: 24793485   Customer No: 000130522"

$stringpostion=StringInStr($string,"Order No:")+10

$ordernumber=StringMid ( $string, $stringpostion,8)

MsgBox(0,"",$ordernumber)

What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Posted

The following code should work for you:

; Define $text - can be gotten with ClipGet() as well
$text = "/dev/pts/12: Connected to Virtual Machine 'pick0:LINUX'." & @CRLF & "TEST CORP SALES (DETAIL)  Primary Whse: 6   123456        08:22:10 05/01/09" & @CRLF & "Trans Cd: A (A,B,D,F,I,L,M,S,/)   Order No: 24793485   Customer No: 000130522" & @CRLF & "Order for: TEST MXPQFG5F3C            Placed By: WJB" & @CRLF & "Line PB Price... Catalog No Catalog Color. * Description........... Amount...." & @CRLF & "     W" & @CRLF & "" & @CRLF & "Weight:     1 ================== Pieces:        1 ====== Amount:      11.99" & @CRLF & "   1  1 11.99 K420     Athletic Gold    PA Pique Sport Shirt        11.99" & @CRLF & "   6                                    M:    1" & @CRLF

; Find out where the Order Starts
$orderStart = StringInstr($text, "Order No: ")+10

; Get the Length of the Order Number by getting the first Space after the Order Number Starts
$orderLen = StringInStr($text, chr(32), 0, 1, $orderStart)-$orderStart

; Get a part of the string, starting after Order Number and Ending right before the Space
$orderNumber = StringMid($text, $orderStart, $orderLen);

; Dump to Console to Test
consolewrite($orderNumber)

It takes into account a variable length order number, however if there will ever be anything after the order number besides a space (a carriage return, for example), additional coding would need to be done to take that into account.

Posted

The following code should work for you:

; Define $text - can be gotten with ClipGet() as well
$text = "/dev/pts/12: Connected to Virtual Machine 'pick0:LINUX'." & @CRLF & "TEST CORP SALES (DETAIL)  Primary Whse: 6   123456        08:22:10 05/01/09" & @CRLF & "Trans Cd: A (A,B,D,F,I,L,M,S,/)   Order No: 24793485   Customer No: 000130522" & @CRLF & "Order for: TEST MXPQFG5F3C            Placed By: WJB" & @CRLF & "Line PB Price... Catalog No Catalog Color. * Description........... Amount...." & @CRLF & "     W" & @CRLF & "" & @CRLF & "Weight:     1 ================== Pieces:        1 ====== Amount:      11.99" & @CRLF & "   1  1 11.99 K420     Athletic Gold    PA Pique Sport Shirt        11.99" & @CRLF & "   6                                    M:    1" & @CRLF

; Find out where the Order Starts
$orderStart = StringInstr($text, "Order No: ")+10

; Get the Length of the Order Number by getting the first Space after the Order Number Starts
$orderLen = StringInStr($text, chr(32), 0, 1, $orderStart)-$orderStart

; Get a part of the string, starting after Order Number and Ending right before the Space
$orderNumber = StringMid($text, $orderStart, $orderLen);

; Dump to Console to Test
consolewrite($orderNumber)

It takes into account a variable length order number, however if there will ever be anything after the order number besides a space (a carriage return, for example), additional coding would need to be done to take that into account.

THANK YOU! THANK YOU! THANK YOU!!!! This is exactly what I have been trying to do for the last month! It works perfectly!

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
  • Recently Browsing   0 members

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