UAMike Posted October 4, 2019 Report Share Posted October 4, 2019 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted October 4, 2019 Report Share Posted October 4, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
Cory Posted October 4, 2019 Report Share Posted October 4, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
rberq Posted October 4, 2019 Report Share Posted October 4, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
UAMike Posted October 4, 2019 Author Report Share Posted October 4, 2019 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. Quote Link to comment Share on other sites More sharing options...
UAMike Posted October 4, 2019 Author Report Share Posted October 4, 2019 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. Quote Link to comment Share on other sites More sharing options...
Samrae Posted October 4, 2019 Report Share Posted October 4, 2019 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 "" 1 Quote Link to comment Share on other sites More sharing options...
UAMike Posted October 4, 2019 Author Report Share Posted October 4, 2019 30 minutes ago, Samrae said: Generally, in Windows, this appears as CRLF, not LFCR. Try this: Variable Modify String: Replace "-A%CR%%LF%" in %Temp% with "" Yep, that fixes the issue! Thank you to all! Quote Link to comment Share on other sites More sharing options...
Cory Posted November 13, 2019 Report Share Posted November 13, 2019 You're welcome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.