Jump to content

Help Understanding StringTrimLeft

Recommended Posts

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


          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)


Does not remove anything.

Link to comment
Share on other sites

  • Moderators


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)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:


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


Link to comment
Share on other sites

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 by czardas
Link to comment
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

  • Recently Browsing   0 members

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