473,508 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unicode and reading/writing text files

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>")
Nov 19 '08 #1
1 4813
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/
Nov 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
26563
by: ..... | last post by:
I have an established program that I am changing to allow users to select one of eight languages and have all the label captions change accordingly. I have no problems with English, French, Dutch,...
3
17594
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
8
4019
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
11
3622
by: Patrick Van Esch | last post by:
Hello, I have the following problem of principle: in writing HTML pages containing ancient greek, there are two possibilities: one is to write the unicode characters directly (encoded as two...
18
34069
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
10
1382
by: RobKinney1 | last post by:
Hello everyone... This may sound really stupid, but it is something I have been working on all day and haven't found a solution yet. If you go into Notepad and try the keystroke ALT+4, you get a...
8
9910
by: Richard Schulman | last post by:
Sorry to be back at the goodly well so soon, but... ....when I execute the following -- variable mean_eng_txt being utf-16LE and its datatype nvarchar2(79) in Oracle: cursor.execute("""INSERT...
18
620
by: Chameleon | last post by:
I am trying to #define this: #ifdef UNICODE_STRINGS #define UC16 L typedef wstring String; #else #define UC16 typedef string String; #endif ....
2
2596
by: geniuskanwal | last post by:
Before I begin to explain my problem, I just want to say that I can do the following two things: 1. Using Perl, connect to a MS Access Databse Table and perform the required operations.(Database...
0
820
by: akshaycjoshi | last post by:
namespace consolepractice { class Program { static byte asyncreadbytes; static byte asyncwritebytes; static FileStream fileS; static FileInfo file; ...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.