Solved

converting non-ASCII characters to ASCII plain text in ASP/VB Script

Posted on 2009-05-19
2
749 Views
Last Modified: 2012-05-07
I have an ASP web app that takes a user-submitted CSV file and populates a SQL database table using the data. However, some users are exporting Excel files into CSV format, and its not always plain text. Examples would be typographer's quotes instead of plain text ", fancy apostrophe's instead of ', etc. So I end up with garbage characters in the table.

Is there some way I can reformat the data "on the fly" so the garbage characters will be converted properly? I don't want to simply delete them, they need to be intelligently converted into their corresponding ASCII character, whenever possible. I'm sure there are some characters that can't be converted. In BB Edit (my text editor), if I do a convert-to-ASCII it is smart enough to convert a © to (C), ® to (R), etc. That would be really nice, though not sure if its practical in this case.

I also don't know if this needs to be done on a character-by-character basis (which may slow the app down considerably), or if there is some global way to do the conversion?

I found this script, but can't seem to get it to work:

http://www.robvanderwoude.com/vbstech_files_utf8.php

Would appreciate any advice. Thanks!
0
Comment
Question by:bbdesign
2 Comments
 
LVL 14

Accepted Solution

by:
_Stilgar_ earned 500 total points
ID: 24429844
The code you provided link to does the opposite of what you're after. You are trying to take UTF8 or non-standard ANSI codes and transform them to the limited 256-code ASCII, which exists on all ANSI tables. This has nothing to do with simple conversions, as © exists in all of those codepages, yet you want to convert it to (C) and so on.

As far as I know, this is only possible to do by building a conversion table and replacing them one-by-one. Use the VBScript WChar function to handle Unicode streams correctly (and to convert non-Unicode to Unicode in order to provide correct conversion), and then replace chars one by one, correcting and adding as you go. There are probably tables listing all those characters commonly used, which you could use.

Since Unicode/ANSI handling in ASP/VBscript is limited at best, I'd even consider building a small COM object to do this job, to make sure no codepage is left behind.
0
 

Author Comment

by:bbdesign
ID: 24430895
Thanks for the advice!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now