dealing with strange characters with access, asp and CSVs

I have a problem, i have to create a csv file with an ASP Classic page, taking the data from a MS Access database, all really simple, but in the final file I have tons of strange characters, appearing as squares (unknown character square). I must get rid of those characters, but i really don't know how... have you got some ideas?

this is how I see something on the file: M�NSTERSTRA�E and of course, I don't really know which are the char that give problems...and they are really a lot.

and this is how I write the csv...

dim fs,f,d
            set fs = Server.CreateObject("Scripting.FileSystemObject")
            set f = fs.OpenTextFile(Server.MapPath("clienti.csv"), 2, true,true)
            d = ""


            do while not rs1.EOF 


            d = ""
                For Each fField in RS1.Fields 
                    f.Write(d)
                    f.Write(" ")
                    temp = RS1(fField.Name)
                    if len(trim(temp)) > 0 then
                        f.Write(trim(temp))
                    end if
                    d = ";"    
                Next


            f.WriteLine("")


            rs1.movenext
            loop

            f.Close
            set f = Nothing
            set fs = Nothing

I can't think about making a replace of all the chars, becouse I don't know them before i extract all the clients... I need some workaround for this...

Upvotes: 0

Views: 326

Answers (1)

Tom Collins
Tom Collins

Reputation: 4069

The � means that your browser doesn't recognize that char, so makes a substitute. One example is the "smart quotes" (curly ones) that some applications, like MS Word, substitute for the strait quotes. The default character encoding is ISO-8859-1.

If you don't want those to show up, you have 2 choices. You can delete them, of you can try to find the appropriate substitution.

Either way, first you have to identify all the chars that result in �. To do this, you'll have to go through each char and compare it to this list: http://www.ic.unicamp.br/~stolfi/EXPORT/www/ISO-8859-1-Encoding.html

Once you identify the bad char, you have the choice of just deleting it, or once you figure out what they should be, you can change them to what they should be. For instance, the smart quotes are coded as 147 & 148, so you can just change both of those to strait quotes ("). If you do a search, you'll probably find some code that does most, if not all, of this for you.

Upvotes: 3

Related Questions