Jump to content
xcaliber13

Help Understanding StringTrimLeft

Recommended Posts

xcaliber13

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.

Share this post


Link to post
Share on other sites
czardas
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 by czardas

Share this post


Link to post
Share on other sites
xcaliber13

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.

Share this post


Link to post
Share on other sites
Melba23

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._______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
nend

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 by nend
  • Like 2

Share this post


Link to post
Share on other sites
czardas

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

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

×