MSF Posted May 1, 2009 Posted May 1, 2009 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().
WideBoyDixon Posted May 1, 2009 Posted May 1, 2009 You mean: $text = ClipGet() WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center]
MSF Posted May 1, 2009 Author Posted May 1, 2009 You mean: $text = ClipGet() WBDThat 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!
ChrisFromBoston Posted May 1, 2009 Posted May 1, 2009 (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 May 1, 2009 by ChrisFromBoston
MSF Posted May 1, 2009 Author Posted May 1, 2009 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
Negative1 Posted May 1, 2009 Posted May 1, 2009 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.
ChrisFromBoston Posted May 1, 2009 Posted May 1, 2009 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.
MSF Posted May 1, 2009 Author Posted May 1, 2009 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!
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