Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create Unicode file

Status
Not open for further replies.

prinand

MIS
Jun 13, 2000
98
GB
I want to create a unicode file - and it works OK, EXCEPT it saves 2 codes at the start of the file : FF FE (only see them if you open with a HEX editor...

I saw in thread222-927492 (the only thread that was found when doing a search for "file FF FE" )
a remark that a Unicode file always starts with FF FE

but those 2 codes are exactly why the application that I am trying to feed fails.

if I can remove the FF FE I am fine.....

can I save the file differently and thus prevent that these 2 values are not added at the start ?
 
It is not true that "a Unicode file always starts with FF FE".

a) There are different BOMs (byte order marks) for different UTF formats
b) They are mostly optional, used to help mark a file a UTF, and to supply the endianness of the byte stream

So, if you want to write the file without the bytes you can
 
Somebody call 911! Something happened to strongm before he finished his post!
 
:)

>So, if you want to write the file without the bytes you can

So, if you want to write the file without the bytes, you can do so.
 
SO my ultimate question would still be HOW ???

let me explain in more detail : if I save to a a file
c:\test

it becomes in UTF HEX :
FF FE 43 00 3A 00 5C 00 74 00 etc
the way I saved it, FF FE was at the beginning of the file.

so could someone show me the code to write c:\temp in the above format to a file without the FF FE - it must start immediately with the 43 00 ....

 
>if I save to a a file

Let's start with you telling us how you are currently saving to file. I'm guessing that you are probably using the FileSystemObject, since that is UTF-aware.
 
the dumb (but working) method would be after creating a file, open it as binary , skip 2 bytes and read the rest/write to another file.
 
Sorry, guys, intended to respond last night and show the code, but never touched the PC...

I have resolved it indeed via the dumb method - that is exactly what I do now, but I figured there must be a smarter method....

set fs = CreateObject("Scripting.FileSystemObject")
Set logfilefs = fs.CreateTextFile(Outputfile, true, 2)
lofilefs.writeline("c:\temp")
logfilefs.close


and now I also do

ff = FreeFile
Open Outputfile For Binary As #ff
Raw$ = String$(LOF(ff), 32)
Get #ff, 1, Raw$
Lenght = len(raw$)
Raw1$ = Right(raw$,lenght-2)
put #ff,1,Raw1$
Close #ff

it works, but seems rather stupid... I am sure this can be better.

ps. when I save it as a normal text file
c:\temp becomes in HEX : 43 3A 5C 74 etc
for some reason NTbackup.exe (which is what I want to feed) required this unicode so the zero's 00 in between every character, and I noticed Unicode does that.... so that is why I use the unicode.

I also noticed, if NTbackup saves a file (test.bks) the FF FE is missing, but if you then use any editor, ie. notepad or textpad, it realizes it is unicode, and reads it properly, and if you then save it again, it is still saved in unicode, but they also append FF FE at the start of the file....




 
>set fs = CreateObject("Scripting.FileSystemObject")

Thought so ...

>ie. notepad or textpad, it realizes it is unicode, and reads it properly, and if you then save it again, it is still saved in unicode, but they also append FF FE at the start of the file....

Well, not always. To be honest I've never researched Wordpad on this subject, but Notepad samples the first few bytes of any document that it is opening and applies a checking algorithm to see if it can conclude that it is UTF-8, UTF-16 or ANSI. There are occassions, because of the particular bytes it finds, that it gets this wrong.

However, as you say, if it doesidentify it as UTF it will then save it with the relevant BOM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top