rascal
asked on
How to convert a UNICODE string to ansi in ASP?
We are reading a SQL Server 2000 database and writing its contents out to a text file via our ASP web page.
The problem is that because the fields are defined as ntext, the resulting file is written out as unicode (we're just using the Scripting.FileSystemObject to create a text file and it appears to automatically be saving it as a unicode file).
This is a problem because the 3rd party system we send the text file off to cannot process the unicode data.
We tried casting the SQL field to text (from its original unicode ntext type) but the resulting string was still unicode.
QUESTION: Is there a way in ASP to convert a UNICODE string to ANSI prior to writing it out to the file?
Thanks experts!
The problem is that because the fields are defined as ntext, the resulting file is written out as unicode (we're just using the Scripting.FileSystemObject
This is a problem because the 3rd party system we send the text file off to cannot process the unicode data.
We tried casting the SQL field to text (from its original unicode ntext type) but the resulting string was still unicode.
QUESTION: Is there a way in ASP to convert a UNICODE string to ANSI prior to writing it out to the file?
Thanks experts!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Actually the above solution didn't actually fix the problem (which I hadn't fully realized)
I had to explicitly open the text file in ANSI mode in order to get the resulting file to be ANSI. Just relying on the default open mode for the file still resulted in Unicode.
Here is the code I used:
dim f
const ForReading = 1
const ForWriting = 2
const ForAppending = 8
const TristateUseDefault = -2
const TristateTrue = -1
const TristateFalse = 0
objFSO.CreateTextFile sOutputFilename, 2, true ' 2 = for writing, true = create
set f = objFSO.GetFile(sOutputFile name)
set objFile = f.OpenAsTextStream(ForWrit ing, TristateFalse)
I had to explicitly open the text file in ANSI mode in order to get the resulting file to be ANSI. Just relying on the default open mode for the file still resulted in Unicode.
Here is the code I used:
dim f
const ForReading = 1
const ForWriting = 2
const ForAppending = 8
const TristateUseDefault = -2
const TristateTrue = -1
const TristateFalse = 0
objFSO.CreateTextFile sOutputFilename, 2, true ' 2 = for writing, true = create
set f = objFSO.GetFile(sOutputFile
set objFile = f.OpenAsTextStream(ForWrit
https://www.experts-exchange.com/questions/24375225/How-to-convert-an-ntext-field-to-text-when-reading-from-the-DB.html
Please request that it be deleted.