Jump to content

Recommended Posts

Posted

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.

Posted

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.

  • Moderators
Posted

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

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:

  Reveal hidden contents

 

Posted (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 by czardas

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