Sign in to follow this  
Followers 0
lyonsksd

Parsing for a word that has been wrapped to a new line

3 posts in this topic

Hi,

I have been fighting with a script for a while now. It seems simple enough, but the problem that I am having has to do with finding a word in a clip board. I grab the text from a dos window, put it in the clip board, and then parse it for a certain word. However the word is occasionally wrapped onto a new line. I have googled for ideas on how to fix this as well as searched throughout the forum. Even help couldn't help me.

DLOG,1,20090306,123340,0,17000138,1640,200,0,(1640.068) RX: #SERVINFO: 722,-77,"

T-Mobile","31026",70,0B9A,01,1,,"II",01,6;

or

DLOG,1,20090311,143108,0,72200035,260,200,0,(260.077) RX: #SERVINFO: 722,-82,"T-

Mobile","31026",70,0B9A,02,1,,"II",01,6;

I am not really interested in changing the dos window properties to be more than 80 characters wide, because I can't control where this script will be used.

To check, copy the first DLOG line to the clip board and then run script. The first one will work. The second DLOG line will fail.

This is what I have right now.

CODE
$String = ClipGet() ;store the cmd dump from clipboard into variable.

$Capture = StringRegExpReplace($String, '([][{}()|.?+*\\^])', '\\\1') ;get rid of all special characters

$result = StringInStr($Capture, "RX: #SERVINFO") ;find the start of the info needed.

$result6 = StringTrimLeft($capture, $result + 25) ;add to the count found to get to the string needed

$Result7 = StringStripCR($result6 & Chr(13) & Chr(10)) ;remove all carriage returns and line feeds

$Result8 = Stringleft($result7, 8) ;only take the left 8 characters

$Result9 = StringCompare($Result8, "T-Mobile") ;compare the results to the expected value

If $Result9 = 0 Then

$GSMCARRIER = $Result8

MsgBox(0, "", "'" & $GSMCARRIER & "'" & " was was the carrier detected.")

Else

MsgBox(0, "", "The carrier was not detected. Continue test but mark board")

Endif

I also tried it this way.

CODE
$String = ClipGet() ;store the cmd dump from clipboard into variable.

$Capture = StringRegExpReplace($String, '([][{}()|.?+*\\^])', '\\\1') ;get rid of all special characters

$result = StringInStr($Capture, "RX: #SERVINFO") ;find the start of the info needed.

$result6 = StringTrimLeft($capture, $result + 23)

$Result7 = StringStripCR($result6 & Chr(13) & Chr(10))

$Result8 = Stringleft($result7, 9)

$Trythis = StringStripWS($Result8, 8)

$Result9 = StringCompare($Trythis, "T-Mobile")

If $Result9 = 0 Then

$GSMCARRIER = $Result8

MsgBox(0, "", "'" & $GSMCARRIER & "'" & " was was the carrier detected.")

Else

MsgBox(0, "", "The carrier was not detected. Continue test but mark board")

Endif

In this method, it does see the word T-Mobile, but prints it out on two lines.

Is there any way to make the "word wrapped" capture lines to be only one line so I can parse it correctly?

Thanks

Share this post


Link to post
Share on other sites



lyonsksd,

Use StringReplace to get rid of any @CRLF and then use StringSplit on the quotation marks. The following works for me using both strings and also returns "not found" for anything without quotation marks:

$sString = ClipGet()      ;store the cmd dump from clipboard into variable.

$sString = StringReplace($sString, @CRLF, "")
$aResult = Stringsplit($sString, '"')
If $aResult[0] > 1 Then
    MsgBox(0, "", "'" & $aResult[2] & "'" & " was was the carrier detected.")
Else
    MsgBox(0, "", "The carrier was not detected. Continue test but mark board")
EndIf

I hope this is what you wanted.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

lyonsksd,

Use StringReplace to get rid of any @CRLF and then use StringSplit on the quotation marks. The following works for me using both strings and also returns "not found" for anything without quotation marks:

$sString = ClipGet()     ;store the cmd dump from clipboard into variable.

$sString = StringReplace($sString, @CRLF, "")
$aResult = Stringsplit($sString, '"')
If $aResult[0] > 1 Then
    MsgBox(0, "", "'" & $aResult[2] & "'" & " was was the carrier detected.")
Else
    MsgBox(0, "", "The carrier was not detected. Continue test but mark board")
EndIf

I hope this is what you wanted.

M23

Works great. I didn't think of trying the StringReplace. I thought that the StringStripCR would have taken care of that.

Thanks

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