Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > unicode and reading/writing text files

Reply
Thread Tools

unicode and reading/writing text files

 
 
Devin
Guest
Posts: n/a
 
      11-19-2008
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>")
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-19-2008
Devin wrote:
> 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python unicode utf-8 characters and MySQL unicode utf-8 characters Grzegorz Śliwiński Python 2 01-19-2011 07:31 AM
Help for Unicode char and Unicode char based string in Ruby Chirag Mistry Ruby 6 02-08-2008 12:45 PM
Reading unicode text files Wx C++ 1 05-22-2007 07:46 AM
Text files read multiple files into single file, and then recreate the multiple files googlinggoogler@hotmail.com Python 4 02-13-2005 05:44 PM
how do I read unicode text files? Boris C++ 0 10-28-2003 10:52 AM



Advertisments