Convert text to ASCII and back again

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
weklica
Newbie
Posts: 6
Joined: Thu May 27, 2010 10:19 pm

Convert text to ASCII and back again

Post by weklica » Mon Aug 30, 2010 2:43 pm

All:

Below, I have pasted code to a .vbs script I am using to try and change all of the little rectangles that appear in a text file when opened in windows after if the file was created on Linux or MACOSX. Basically, instead of breaking the line into separate physical lines, it creates a little rectangular icon. The ASCII value for carriage returns or new lines from MACOSX is 10 and the New Line ASCII value in windows is 13. If I could get the entire text document converted to ASCII, I could replace all of the 10's for 13's (or vice versa). This way, when I convert it back FROM ASCII TO TEXT, the script below would have made all carriage returns WINDOWS native and I could move on with my life. Please help if you have any thoughts if the ASCII feature of macroscheduler can do this type of character conversion throughout a file. Thanks in advance!

~Jesse

Code: Select all

Const ForReading = 1 
Const ForWriting = 2 
 
strFileName = Wscript.Arguments(0) 
strOldText = "vbCr" 
strNewText = "vbCrLf" 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile(strFileName, ForReading) 
 
strText = objFile.ReadAll 
objFile.Close 
strNewText = Replace(strText, strOldText, strNewText,1) 
 
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting) 
objFile.WriteLine strNewText 
objFile.Close
Jesse

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Mon Aug 30, 2010 2:53 pm

A quick thought before we go any further...


Did you get this file by a FTP process?

If so, then change the mode from binary to ASCII and FTP
will correctly translate the EOL (end of line) characters for
you automatically.


If you are doing some sort of copy over a network, then you
might want to consider doing FTP instead as it correctly handles
this situation for you.

If this does not apply in your situation..... just say so, and I'm sure we can come up with another technique.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Aug 30, 2010 3:29 pm

If the only characters of concern are:
"Line feed" ASCII character 10
and
"Carriage Return" ASCII character 13

These are handled as system variables in Macro Scheduler.
variable "LF" = ASCII character 10
variable "CR" = ASCII character 13
variable "CRLF" = ASCII characters 13,10

If you know exactly what characters you want to convert from and to you could easily use the Macro Scheduler StringReplace> function.

For example: To change all UNIX line feed characters (ASCII 10) to DOS style Carriage return / line feed (ASCII 13,10) you would need only to set your text to a variable then do one StringReplace>.

Code: Select all

ReadFile>C:\Path\filetoread.txt,data
StringReplace>data,"LF",%CRLF%,data

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts