Unicode text replace

I need to do a text replace action to set a version in a file. This has ben working fine in th epast, but the file has now been changed to be Unicode format. When I do the text replace now it corrupts the file. Is there a way to do a text replacement in a unicode file?

Thanks,

     Keith

Hi Keith,

What Unicode format is the file in? UTF-8?

Regards,

Angus


sigh I’m not 100% sure. The developer says he saved it from Notepad as “Unicode”. I just tried saving it from Notepad and it gives me the choices of:
ANSI
Unicode
Unicode big endian
UTF-8

So I’m not exactly sure what format notepad saves a file in when one specifies “Unicode”. Any clue how to tell what it really is?

I’m checking with the developer to figure out why we’re using this format.

sigh

Keith

My developer is clueless as to what format it’s in. he just knows that Visual Studio wants it this way. sigh Ever want to go apply a cluestick to someone’s head?

I’m guessing that since it differentiates “Unicode” from “UTF-8”, and gives and option for “big endian”, that it means UTF-16 when it says Unicode. Microsoft’s web page about the formats in Notepad (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/win_notepad_utf_description.mspx?mfr=true) doesn’t help much, either. I guess they were afraid that having UTF-8 on the page is scary enough and they don’t dare put another scary acronym like UTF-16 on the same page, even though it would be really nice to know if that’s really the standard they’re using.

Ok, the Wikipedia page (http://en.wikipedia.org/wiki/Notepad) for Notepad says it does UTF-16 and UTF-8 and mentions it does both Endians of UTF-16, so this is pretty sure to be UTF-16.

Keith

Thanks Keith. Visual Studio will accept UTF-8 as well, re-saving the file as UTF-8 may solve your problem, if that’s an option for you.

I’ll take a look and see what else we can do about this.

Regards,

Angus

When I try and replace text in a file in Unicode Little Endian encoding (first 2 bytes = “\xFF\xFE”) format the file gets corrupted.

Regards,
Andrew

Hi Andrew

Finalbuilder is not really unicode aware at this time.. I'm pretty sure the text replace action just treats the file as ascii. Unicode support is one of the focuses for the next major version of FinalBuilder.

You will probably need to resort to script (using the Run Script) action.

 

I ran into this Unicode limitation trying to write an Automise 3.0 script to analyze NTBackup log files, which are written in Unicode. I was able to work around it by adapting a VBScript from MSDN and creating a temp file for the analysis.

Before running the VBScript below, set the following variables:

LogFilePathAndName_Original - the original file (in Unicode)
LogFilePathAndName - the temp file (used in the remainder of the Automise script)

Mark

' Adapted from "Copy a Unicode File to an ANSI File" under
' Windows Installer Scripting Examples.
' http://msdn.microsoft.com/en-us/library/aa368046(VS.85).aspx

Const ForReading = 1
Const FailIfNotExist = 0
Const OpenAsDefault = -2
Const OverwriteIfExist = -1
Const OpenAsASCII = 0

Set FileSys = CreateObject("Scripting.FileSystemObject")
Set inStream  = FileSys.OpenTextFile(LogFilePathAndName_Original, ForReading, FailIfNotExist, OpenAsDefault)
Set outStream = FileSys.CreateTextFile(LogFilePathAndName, OverwriteIfExist, OpenAsASCII)
Do
    inLine = inStream.ReadLine
    outStream.WriteLine inLine
Loop Until inStream.AtEndOfStream
inStream.Close
outStream.Close