TheCrimsonCrusader Posted August 16, 2011 Posted August 16, 2011 (edited) Greetings,The script below will read the testfile.txt, that has the following contents:path=c:\windowsIt will then proceed to strip any text to the left of the equal sign including the equal sign i.e. so it shows up as c:\windows, which is the expected behavior. Alternately, I would like to strip any text that is right of the equal sign including the equal sign instead. Whether I change the "StringTrimLeft" to "StringTrimRight" or change the "1"/"-1" entries on the "$LeftofEqual" variable or both, I don't get the hopeful results of it showing up as pathI can't do any specific trim numbers as that will vary, so that's why I am acquiring the number of characters leading up to the equal sign, but I can't seem to reverse it where it acquires the number of characters from the right side of it instead. The full code is below:$readline = FileReadLine("testfile.txt",1) $LeftofEqual=StringInStr($readline, "=", 1, -1) $result = StringTrimLeft ($readline,$LeftofEqual) MsgBox(0,"",$resultThanks in advance for any assistance that can be provided. Edited August 16, 2011 by TheCrimsonCrusader
enaiman Posted August 17, 2011 Posted August 17, 2011 (edited) Here you go: $readline = FileReadLine("testfile.txt",1) $LeftofEqual=StringInStr($readline, "=", 1, -1) $result = StringTrimLeft ($readline,$LeftofEqual) MsgBox(0,"",$result) $result = StringTrimRight($readline, StringLen($readline)-$LeftofEqual+1) MsgBox(0,"",$result) To strip the right part - you need to consider string length. Edited August 17, 2011 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
Moderators Melba23 Posted August 17, 2011 Moderators Posted August 17, 2011 TheCrimsonCrusader, Or you can use a SRE like this to split on the = sign directly: $sText = "path=c:\windows" $sLeft = StringRegExpReplace($sText, "(.*)=(.*)", "$1") $sRight = StringRegExpReplace($sText, "(.*)=(.*)", "$2") MsgBox(0, "Result", $sLeft & @CRLF & $sRight) SRE explanation: (.*) - Capture any number of characters = - Do not capture an = sign (.*) - Capture any number of characters $1 - Replace with first captured group $2 - Replace with second captured group Please ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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