Jump to content
Sign in to follow this  

Convert ANSI CSV to Unicode CSV Issues

Recommended Posts

I need help converting an ANSI CSV file to a Unicode CSV file.

The ANSI CSV file may contain a line like:

18,"Alpha, Beta & Capa","1234567","","",0,0,"","","","","",0,0,0,"",0,0,"","","","",0,0,0

When I use the below code to create the Unicode CSV file it converts ALL commas to chr(9) aka Horizontal Tab.

I need the commas within the "" to remain.

What can I do to fix this?

Code Sample:

$ANSI = FileRead($FileToConvert)
    $ANSI2 = StringReplace($ANSI,'"','')
    $Unicode = FileOpen($Converted,32+2) ;32=Unicode
    FileWrite($Unicode, $ANSI2)

Any Help is appreciated.

[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!

Share this post

Link to post
Share on other sites

I don't understand your question and I'm tempted to say you don't get it either.

The example line you give shouldn't change between ANSI and Unicode, since it doesn't contain any character outside lower ANSI (which map identically to Unicode codepoints).

ANSI is a character set and implies a 8-bit encoding. Unicode is a (much larger) character set and does _not_ define an encoding. Unicode can be encoded into UTF-7 (deprecated) UTF-8 (recommended for most uses), UTF-16LE, UTF-16BE, UTF-32, all of them with or without BOM. There are other encoding for special/localied purposes.

Why do you think you need to remove all double-quotes like you're doing? That destroys the structure of your records.

Remove the StringReplace, select the Unicode encoding you need (is it _really_ UTF-16LE?) and you should be fine.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...