Jump to content
Macro Express Forums

Removing multiple blank lines


Recommended Posts

I use macros to remove lines of text from a larger block of text. I am using the Variable Modify String command to replace unwanted text with a blank. The problem of course is that I then end up with blank lines when I wanted was to remove the text and carriage return. Here is an example:

 

The list contains:

 

-A

-B

-C

-D

-E

 

End of list.

 

What I will end up with after using Variable Modify String is something like this:

 

The list contains:

 

 

-B

-C

 

-E

 

End of list.

 

What I wanted was it to be formatted like this:

 

 

The list contains:

 

-B

-C

-E

 

End of list.

 

How can I accomplish this? I tried using Trim CR/LF, but then I am removing all the carriage returns.

Link to comment
Share on other sites

When you do the replace, include a newline set. A newline in Window is two non-printing characters carriage return and line feed. 0x0d and 0x0a. That's what gives you the line break. Click here for my instruction on how to create them in MEP. You will want to add them to the end of the string you want to replace.

  • Like 1
Link to comment
Share on other sites

2D 41 0D 0A 2D 42 0D 0A 2D 43 0D 0A 2D 44 0D 0A 2D 45

THis is how your text actually looks like to the computer internally. Each of those pairs is a hexadecimal representation of the binary. Each represents a byte, 8 bits, of data. By applying the ASCII encoding, you will get the letters and such that you are used to seeing. Click here to see a table of the value, E.G. 2D is a hyphen, 41 is "A". I think it helps people if they can see what it's happening behind the scenes.

 

And in binary. How it actually is in memory or on disk. Cut those into chunks of 8 and you can manually decode them yourself. If you're really bored 🙂

0010110101000001000010100010110101000010000010100010110101000011000010100010110101000100000010100010110101000101

  • Like 1
Link to comment
Share on other sites

This might work:

Step 1: Replace all CR/LF with "!@#$%^&" or some other such visible (or non-printable) string that will never occur naturally. 

Step 2: Instead of replacing "-A" with a blank, replace "-A!@#$%^&" with a blank.  In this way, only [what used to be] CR/LF attached to unwanted text will be eliminated, along with the unwanted text.

Step 3: Replace all remaining "!@#$%^&" with CR/LF. 

  • Like 1
Link to comment
Share on other sites

5 hours ago, Cory said:

When you do the replace, include a newline set. A newline in Window is two non-printing characters carriage return and line feed. 0x0d and 0x0a. That's what gives you the line break. Click here for my instruction on how to create them in MEP. You will want to add them to the end of the string you want to replace.

 

Thanks for the info. I am trying this method but I am sure that I am misunderstanding something. I declared the variable as you suggested:

Variable Set to ASCII Char 9 to %Tab%
Variable Set to ASCII Char 10 to %LF%
Variable Set to ASCII Char 13 to %CR%

 

I am not getting the desired outcome. Where do you put the %LF% and %CR% variable within the Modify String command? I tried putting it in 'text to replace' ("-A%LF%%CR%") but then it ends up trying to replace %LF%%CR% as a string value.

Link to comment
Share on other sites

1 hour ago, rberq said:

This might work:

Step 1: Replace all CR/LF with "!@#$%^&" or some other such visible (or non-printable) string that will never occur naturally. 

Step 2: Instead of replacing "-A" with a blank, replace "-A!@#$%^&" with a blank.  In this way, only [what used to be] CR/LF attached to unwanted text will be eliminated, along with the unwanted text.

Step 3: Replace all remaining "!@#$%^&" with CR/LF. 

 

Thanks for the input. I agree that this would work... however, due to the fact that I am getting my data from a shared/synced OneNote document, I wouldn't be able to add the nonsense string as would be called for using this method.

Link to comment
Share on other sites

17 minutes ago, UAMike said:

I am not getting the desired outcome. Where do you put the %LF% and %CR% variable within the Modify String command? I tried putting it in 'text to replace' ("-A%LF%%CR%") but then it ends up trying to replace %LF%%CR% as a string value.

Generally, in Windows, this appears as CRLF, not LFCR.  Try this:

  Variable Modify String: Replace "-A%CR%%LF%" in %Temp% with ""

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

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...
×
×
  • Create New...