techtraf Posted October 20, 2010 Report Share Posted October 20, 2010 Hello all, I would like to know how I can delete the last character at the end of the file. It's call End-Mark file. It looks like a square (). I would like to know if someone already have a macro to this step or let me know how to do it. I'm currently using macro pro. Thank you all, Quote Link to comment Share on other sites More sharing options...
techtraf Posted October 20, 2010 Author Report Share Posted October 20, 2010 Please anyone, I would like to delete the EOF marker in text file. In this case is locate at the very end of the file (left corner). Is there a way to remove that EOF marker programmatically using the macro script commmand? Please let me know. Thanks again, Quote Link to comment Share on other sites More sharing options...
kevin Posted October 21, 2010 Report Share Posted October 21, 2010 I can think of several ways to do this. Here are three. If I remember correctly, the EOF character is 1A hex or 26 decimal. If the EOF character only exists at the end of the file then this technique will work. It deletes the EOF character by replacing it with nothing. // Method 1 - Replace EOF character with nothing. Variable Set to ASCII Char 26 to %EOF% Variable Set String set %FileContent% to the contents of c:\InFile.txt Variable Modify String: Replace "%EOF%" in %FileContent% with "" Variable Modify String: Save %FileContent% to "c:\OutFile.txt" If you are not sure of the EOF character or whether it exists more than once in the file you may want to try Method 2 or 3. Method 2 deletes the last character. // Method 2 - Copy all but last character using Delete Variable Set String set %FileContent% to the contents of c:\InFile.txt Variable Set Integer %Length% to the length of variable %FileContent% Variable Modify Integer %Length%: Decrement Variable Modify String %FileContent%: Delete a substring starting at %Length% and 1 characters long Variable Modify String: Save %FileContent% to "c:\OutFile.txt" Method 3 copies all but the last character. // Method 3 - Copy all but last character using Copy Variable Set String set %FileContent% to the contents of c:\InFile.txt Variable Set Integer %Length% to the length of variable %FileContent% Variable Modify Integer %Length%: Decrement Variable Modify String: Copy a substring in %FileContent%, starting at 1 and %Length% characters long to %FileContentOut% Variable Modify String: Save %FileContentOut% to "c:\OutFile.txt" To experiment with each of these copy the following code and paste it into a macro: <COMMENT/> <COMMENT/> <COMMENT Value="Method 1 - Replace EOF character with nothing."/> <VARIABLE SET TO ASCII CHAR Value="26" Destination="%EOF%"/> <VARIABLE SET STRING Option="\x03" Destination="%FileContent%" Filename="c:\\InFile.txt" Strip="FALSE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%FileContent%" ToReplace="%EOF%" All="FALSE" IgnoreCase="FALSE"/> <VARIABLE MODIFY STRING Option="\x11" Destination="%FileContent%" Filename="c:\\OutFile.txt" CRLF="FALSE"/> <COMMENT/> <COMMENT/> <COMMENT Value="Method 2 - Copy all but last character using Delete"/> <VARIABLE SET STRING Option="\x03" Destination="%FileContent%" Filename="c:\\InFile.txt" Strip="FALSE"/> <VARIABLE SET INTEGER Option="\x0D" Destination="%Length%" Text_Variable="%FileContent%"/> <VARIABLE MODIFY INTEGER Option="\x08" Destination="%Length%"/> <VARIABLE MODIFY STRING Option="\x0A" Destination="%FileContent%" Start="%Length%" Count="1"/> <VARIABLE MODIFY STRING Option="\x11" Destination="%FileContent%" Filename="c:\\OutFile.txt" CRLF="FALSE"/> <COMMENT/> <COMMENT/> <COMMENT Value="Method 3 - Copy all but last character using Copy"/> <VARIABLE SET STRING Option="\x03" Destination="%FileContent%" Filename="c:\\InFile.txt" Strip="FALSE"/> <VARIABLE SET INTEGER Option="\x0D" Destination="%Length%" Text_Variable="%FileContent%"/> <VARIABLE MODIFY INTEGER Option="\x08" Destination="%Length%"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%FileContentOut%" Variable="%FileContent%" Start="1" Count="%Length%"/> <VARIABLE MODIFY STRING Option="\x11" Destination="%FileContentOut%" Filename="c:\\OutFile.txt" CRLF="FALSE"/> Quote Link to comment Share on other sites More sharing options...
techtraf Posted October 22, 2010 Author Report Share Posted October 22, 2010 Thank you very much Kevin. The first code is working PERFECT for me. I appreciate your help. 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.