View Full Version : writing file with accented characters
esthera
05-18-2006, 10:36 AM
i'm writing a file withy accented characters -- like the french characters and when the file is created it does not keep the accents on the characters --
what can i do to fix this?
degsy
05-18-2006, 04:21 PM
It is for HTML output?
You can convert them to Character Entities
http://www.w3schools.com/tags/ref_entities.asp
esthera
05-18-2006, 04:42 PM
so are you saying I should convert all the characters to their html equivalent before writing to the text file??
any function that just replaces all out there that you know of??
ghell
05-20-2006, 11:25 PM
if you are using the filesystemobject when you open the text stream make sure you set it to unicode.
see the "fso reference" link in my signature. in particular this page:
http://www.sloppycode.net/Reference/FSO/Ref-95.html
esthera
05-21-2006, 08:35 AM
to write to the file i'm using the following function and callign it with ascii-charset -- is this my problem. I did this as I was having other issues and writing the files like this fixed it.
Function SaveTextData(FileName, Text, CharSet)
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
End If
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
esthera
05-21-2006, 10:55 AM
I also tried the following
langaugefacts=replace(languagefacts,"à","à")
languagefacts=replace(languagefacts,"á","á")
languagefacts=replace(languagefacts,"â","â")
languagefacts=replace(languagefacts,"ã","ã")
languagefacts=replace(languagefacts("ä","ä")
lanugagefacts=replace(lanugagefacts("å","å")
but then I had to save it as unicode to conserve the french character and when I did I get an asp error when running the file:
Active Server Pages error 'ASP 0239'
Cannot process file
/createfiles.asp, line 1
UNICODE ASP files are not supported.
Please advise?
ghell
05-21-2006, 06:39 PM
asp source files must be ascii encoded not unicode. writing and reading unicode to an external file (such as a .txt file or whatever) is, however, possible without the need for adodb.streams.Dim objFSO, objTextStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Open file for writing, create new if it doesnt exist and open in unicode encoding.
Set objTextStream = objFSO.OpenTextFile("textfile.txt", 2, true, -1)
objTextStream.WriteLine("Hello there. This would be a better test if it had unicode in it but you")
objTextStream.WriteLine("can't put unicode in the ASP file to test so it would need to be UTF-8")
objTextStream.WriteLine("form submitted or use long escapes in the querystring.")
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
esthera
05-24-2006, 08:26 AM
tried this -- the problem is I am creating a asp file so it won't allow unicode -- but I need to preserve the french characters -- anyway around this???
ghell
05-24-2006, 12:56 PM
Not as far as i know, the asp processor cannot interpret unicode files so you cant just put them in it. You may be able to wrap strings of text with a urlencode/urldecode or just do as said earlier and use the &#....; thing to get the htmlencoding of those characters. I'm not sure why french would require unicode though they should all be in the ascii if you use the correct extended ascii format to display the page (just setting the wrong character set will change what those characters look like)
é for example is certainly in ISO-8859-1.
esthera
05-24-2006, 01:06 PM
i'm using the meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
and they are all not showing.
what do you mean by using urlencode and where does this fit in.
i'm pulling data from a db (that has these characters) and creating from it a asp file.
ghell
05-24-2006, 01:43 PM
Ok try UTF-8 and if that doesnt work UTF-16
Otherwise.. if you are pulling the offending text from a database you could try just usingResponse.Write Response.HTMLEncode(strFrenchText)
url encoding is like %20 can be decoded to a space (0x20 = 32 = ascii space) and there are also url formats for unicode that look a bit strange to me but hey, i was hoping you could just decode them so that they would print fine into the output stream but wouoldnt be in the actual asp source. if your french characters are all in an external data source there is no need to write the character to a .asp page so this wouldnt be required.
esthera
05-24-2006, 02:08 PM
what do you mean by UTF-16 -- how do I do that?
also it works if I do response.write directly from the db- it only doesn't show up in the file written.
ghell
05-24-2006, 02:16 PM
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
is preferred
<meta http-equiv="Content-Type" content="text/html; charset=utf-16">
may be possible (there are certainly utf 7, 8, 16 and 32s)
try just writing it direct from the database with utf-8, if that doesnt work try uf-16, if tht doesnt work go back to iso/utf-8 and try with Respose.HTMLEncode() then try with utf-8 and 16 if that still doesnt work
One of those may work, im not sure to be honest but that would be the logical order to try them in :)
on a side note i believe the web is based on utf-8 in general so maybe it would work if you just took that meta line out totally and tried writing it normally.
you should also test in different browsers. When i use firefox a lot of sites appear with ?s instead of 's for some reason (probably made in ms word and its a funny angled ' or something silly like that, or just firefox and ie use diff default character sets more likely.)
esthera
05-24-2006, 02:21 PM
htmlencode worked - thanks
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.