unicode and reading/writing text files

Discussion in 'ASP General' started by Devin, Nov 19, 2008.

  1. Devin

    Devin Guest

    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>")
     
    Devin, Nov 19, 2008
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Nov 19, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TC
    Replies:
    3
    Views:
    26,208
    jessica
    May 19, 2004
  2. Stephen
    Replies:
    1
    Views:
    677
    Kevin Spencer
    Mar 16, 2006
  3. Wx
    Replies:
    1
    Views:
    427
    Alf P. Steinbach
    May 22, 2007
  4. Lex Syntax
    Replies:
    2
    Views:
    1,441
    Lex Syntax
    Jun 21, 2011
  5. Replies:
    3
    Views:
    183
    Bob Barrows [MVP]
    Jan 25, 2006
Loading...

Share This Page