Jump to content
Macro Express Forums

Left trim not working?


Recommended Posts

ME Pro Help says:

Trim

The Trim option removes all spaces and control characters on the left and on the right of the text string variable being modified.

 

I made a file called C:\trim-test.txt containing these 3 lines:

     5 blanks before this text
     6 blanks before this text
       8 blanks before this text

 

 

This macro simply copies that text to the clipboard, sets a variable, and left trims it.

 

Program Launch: "NOTEPAD.EXE" (Normal)
Parameters: C:\trim-test.txt
Text Type (Simulate Keystrokes): <CONTROL>a // Select all text.
Delay: 100 milliseconds
Text Type (Simulate Keystrokes): <CONTROL>c // Copy all text.
Delay: 100 milliseconds
Variable Set String %T[1]% from the clipboard contents
Variable Modify String %T[1]%: Trim
Text Box Display: Result after left trim

 

So why are the left spaces still present?

 

 

--

Terry, East Grinstead, UK

post-1217-127333291557_thumb.jpg

TrimNotWorking.mex

Link to comment
Share on other sites

It is working. It's removing the left most spaces in the variable. Let me explain.

Say I have the text " something" in the var %MyText% that begins with two spaces and left trim it I will get "something" with no spaces. So far so good, yeah? Now consider you have text like this:

 

Line1

Line2

 

Where each line begins with two spaces. If we left trim it we will get

 

Line1

Line2

 

The reason is because the spaces are not on the left of the variable. Don’t forget each line has an end of line character but to the computer it's all one long 'string'. EG " Line1__ Line2" where the two underscores represent the CR and LF (Carriage Return and Line Feed) characters. So those spaces are in the middle. Here's how it looks in a hex editor. This is the same text as my first example. The hex values on the left, the ACSII text at the right. Notice that it's one long string, not two lines. In this example you can see 20 is a space, 0D is a CR, 0A is a LF and ones like 4C are printing characters, in this case "L". See how the second group of spaces are not on the left end?

post-281-127333449026_thumb.png

Link to comment
Share on other sites

If your goal is to get text into a string var there's a much simpler way than opening notepad and grabbing the text with the clipboard. Consider using the command Varaible Set String > Set Value from File. I think this will work much better for you.

Link to comment
Share on other sites

Here's a sample macro of how to do that.

TerryTrim.mex

 

Many thanks Cory, that works a treat.

 

The real case is copying KML from Google Earth. I could do it by pasting straight to my text editor, TextPad, and using its built-in macro 'Delete Left Blanks'. But I'm trying to emulate your practice of doing as much as possible with ME Pro's own text variables. Takes a bit more coding, but probably more satisfying overall. Maybe faster too.

 

BTW, I realised the reason while taking a break shortly after my post, and came back to edit it, but you and Paul beat me to it. Saturday too - don't normally find you around then!

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Takes a bit more coding, but probably more satisfying overall. Maybe faster too.
It does and it's worth it. And unless you have hundreds of thousands of records anything done invisibly is practically instantaneous and does not interfere with the user.
The real case is copying KML from Google Earth
I mess with this stuff as well. In fact this weekend I discovered that my Garmin GPS stores most all of it's data in XML. Now I can write my own program, graph spreadsheets and what have you from my track logs. Very cool.But if you're dealing with XML you should not need to trim. You can use these tags to extract the data directly.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...