Jump to content
Macro Express Forums

Replacing Carriage Returns With Commas


shaidyn

Recommended Posts

Hey there!

 

This is my first post, so my apologies if this topic has been widely discussed.

 

I have a macro that I want to copy a list of names, and then remove all the carriage returns with commas, so that it can be brough into an existing excell spreadsheet without heavy modification.

 

Right now I highlight the text, run the macro, and it copies it into the clipboard, then assigns it to %T1%. I've tried a few things, but all I can do is remove the CR/LF, I can't get the macro to insert commas where the CRs used to be.

 

It's late and I'm tired, but I hope there's a way to do this.

Link to comment
Share on other sites

I have a write up that will help you on my website. Check out this page on Hex editors and this page on CRLF and TAB.

 

In cases like these I create a text var that represents CRLF and use it in the Replace Substring part of the Variable Modify String command. Works slick.

 

Also you should know that if you are using lists from Excel or other Office apps the format used on the clipboard is a tab seperated file which once can easily manipulate in ME.

Link to comment
Share on other sites

Hmmm, it seems like I've opened quite the can of worms. Thanks so much for the information so far, it looks like my macro building is about to move to the next level.

 

One thing that I'm missing is how to make macro express recognize the hex line breaks so that I can modify them as I see fit.

 

I want to turn this:

 

Tom

Dick

Harry

 

into this:

 

Tom,Dick,Harry

 

What I have right now is this:

 

Clipboard Copy

Variable Set String %T1% from Clipboard

Wait Left Mouse Click

Text Type: %T1%

 

<CLIPC><TVAR2:01:03:><WAITLM:000><TEXTTYPE:%T1%>

 

Somewhere in that I need it to recognize the carriage returns and turn them into commas. I'm a bit lost still. Any advice?

Link to comment
Share on other sites

This may not be elegant, but hopefully it will give you some ideas.

--Dennis

 

// Set variable T2 to Carriage Return
Variable Set %T2% to ASCII Char of 13
// Set variable T3 to Line Feed
Variable Set %T3% to ASCII Char of 10
// Combine Carriage Return & Line Feed (CR/LF) into variable T4
Variable Set String %T4% "%T2%%T3%"
// Get string
Clipboard Copy
Variable Set String %T1% from Clipboard
// Replace CR/LFs with commas
Replace "%T4%" with "," in %T1%

// If string now ends with a comma, delete it and add trailing CR/LF
// First, get the length of the string
Variable Set Integer %N1% from Length of Variable %T1%
// Next, get the last character
Variable Modify String: Copy Part of %T1% to %T5%
// If that last character is a comma, replace it with the CR/LF, otherwise do nothing
If Variable %T5% = ","
 Variable Modify String: Delete Part of %T1%
 Variable Modify String: Append "%T4%" to %T1%
End If

Wait Left Mouse Click
Text Type: %T1%


<REM2:Set variable T2 to Carriage Return><ASCIIC:2:1:13><REM2:Set variable T3 to Line Feed><ASCIIC:3:1:10><REM2:Combine Carriage Return & Line Feed (CR/LF) into variable T4><TVAR2:04:01:%T2%%T3%><REM2:Get string><CLIPC><TVAR2:01:03:><REM2:Replace CR/LFs with commas><TMVAR2:21:01:01:000:000:%T4%,><REM2:><REM2:If string now ends with a comma, delete it and add trailing CR/LF><REM2:First, get the length of the string><IVAR2:01:12:1><REM2:Next, get the last character><TMVAR2:10:05:01:N01:001:><REM2:If that last character is a comma, replace it with the CR/LF, otherwise do nothing><IFVAR2:1:05:1:,><TMVAR2:11:01:00:N01:001:><TMVAR2:07:01:00:000:000:%T4%><ENDIF><REM2:><WAITLM:000><TEXTTYPE:%T1%>

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