Connecting Tech Pros Worldwide Help | Site Map

unicode and reading/writing text files

  #1  
Old November 19th, 2008, 05:55 PM
Devin
Guest
 
Posts: n/a
Hi, I'm working with a csv file that contains Chinese characters.
IfI drag and drop the csv file into firefox, it displays exactly as I
would expect. The English and Chinese characters both appear
correctly.

When I process the file with a script the Chinese characters don't
decode/encode properly. Any suggestions?
(this is actually a vbscript run locally, hope thats not an issue with
anybody)

Code:

option explicit
dim fs, fso, fsi, tstream
dim line
dim ifile, ofile
ifile = "x.csv"
ofile = "y.html"

set fs = createObject("scripting.filesystemobject")
set fso = createObject("scripting.filesystemobject")
set fsi = createObject("scripting.filesystemobject")

set fso = fs.createtextfile(ofile,1,-1)

set fsi = fs.getfile(ifile)
set tstream = fsi.openastextstream(1,-1)

fso.writeline("<html><head><meta http-equiv=""Content-
Type""content=""text/html;charset=utf-8"" ></head><body>")

do while not tstream.atendofstream
dim spl,i

line = tstream.readline
line = replace(line, "||", "<br />")
spl = split(line, vbtab)
for i = 0 to ubound(spl)
fso.write(spl(i))
next
fso.writeline("<hr>")
loop

fso.writeline("</body></html>")
  #2  
Old November 19th, 2008, 06:25 PM
Martin Honnen
Guest
 
Posts: n/a

re: unicode and reading/writing text files


Devin wrote:
Quote:
Hi, I'm working with a csv file that contains Chinese characters.
IfI drag and drop the csv file into firefox, it displays exactly as I
would expect. The English and Chinese characters both appear
correctly.
>
When I process the file with a script the Chinese characters don't
decode/encode properly. Any suggestions?
What is the encoding of the file? FSO can do UTF-16 but not UTF-8 for
instance. So you need to find out the encoding of the file and if FSO
can't handle that then perhaps use an ADODB.Stream with the encoding.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need explaination for Unicode funda akshaycjoshi answers 0 October 3rd, 2008 07:32 PM
Text retrieval systems - 1: Introduction JosAH insights 0 July 8th, 2007 09:28 AM
Unicode / cx_Oracle problem Richard Schulman answers 8 September 16th, 2006 09:55 PM
Unicode to ASCII string conversion Ger answers 18 November 21st, 2005 02:23 AM