xcaliber13 Posted June 14, 2016 Share Posted June 14, 2016 Can some get me going in the right direction? Here is what I am trying to understand. I want to find a string ("MSH") and than delete X amount of characters to the left of that string. Does StringTrimLeft do that? Or does StringTrimLeft just deletes characters within the string? How do I do this? Any help would be great thank you. I did search the forums but just didn't find or understand it all. Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2016 Share Posted June 14, 2016 (edited) 6 minutes ago, xcaliber13 said: ... and than delete X amount of characters to the left of that string. Does StringTrimLeft do that? Yes and there is an example in the help file. Edited June 14, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2016 Share Posted June 14, 2016 Here's another example: #include <MsgboxConstants.au3> Local $sString = "123MHS456" Local $iPosition = StringInStr($sString, 'MHS') ; delete everything before 'MHS' $sString = StringTrimLeft($sString, $iPosition -1) MsgBox($MB_OK, "New String", $sString) operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
xcaliber13 Posted June 14, 2016 Author Share Posted June 14, 2016 czardas, Thank you for the reply and the example but here is what I have come up with but it is not working. Can you explain why? #include <file.au3> #include <FileConstants.au3> Local $sFile = FileOpen("C:\Temp\Test.txt") Local $sString = FileRead($sFile) Local $iPosition = StringInStr($sString, "MSH") $sString = StringTrimLeft($iPosition, 39) FileClose($sFile) Does not remove anything. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 14, 2016 Moderators Share Posted June 14, 2016 xcaliber13, You need to specify the string to trim - at the moment you are passing the position of the "MSH" substring, along with some arbitrary value: $sString = StringTrimLeft($sString, $iPosition) 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 Link to comment Share on other sites More sharing options...
nend Posted June 14, 2016 Share Posted June 14, 2016 (edited) Sound like a job for a regulair expression, this is a small online cours to learn it http://regexone.com/ AutoIt support it totaly. I've made a program where you can test the regular expression (made in autoit with source code) Edited June 14, 2016 by nend Synapsee and Skysnake 2 Link to comment Share on other sites More sharing options...
czardas Posted June 14, 2016 Share Posted June 14, 2016 (edited) Melba has explained this, but here to give you more insight, you need to understand the difference between function return values and parameters. Perhaps the following example will make things a bit clearer. Look again at the help file description - particularly the parameters section and compare it with the code below. #include <MsgBoxConstants.au3> $sReturnValue = StringTrimLeft("123MHS456", 3) MsgBox($MB_OK, "Message Title", $sReturnValue) Notice that the number of characters trimmed (3 in the example above) is one less than the starting position of the substring "MHS", which starts at the 4th character: look again at the example I posted earlier. Also modify the example in this post and observe the differences to better understand these important points. Edited June 14, 2016 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
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