• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2113
  • Last Modified:

is csv file in ansi format

how can we know what format the csv flat file was saved as? ANSI or UNICODE or UTF-8?
0
25112
Asked:
25112
  • 3
  • 2
1 Solution
 
Dan CraciunIT ConsultantCommented:
Header. Look at the first bytes.

Unicode: FF FE
UTF8: EF BB BF

HTH,
Dan
0
 
25112Author Commented:
Dan, can you guide me how to find the header info. I used CSVed.exe, but i don't spot the header there..

thanks.
0
 
Dan CraciunIT ConsultantCommented:
Here's a simple PowerShell script to test the first bytes:
#test if a file is ASCII, Unicode or UTF-8 encoded
#Q_28386979 on E-E
$inputFile="X:\your\path\file.csv"

$encoding = "ASCII"
$firstBytes = get-content $inputFile -Encoding Byte -TotalCount 3

if ($firstBytes[0] -eq 239 -and $firstBytes[1] -eq 187 -and $firstBytes[2] -eq 191) {
    $encoding = "UTF-8"
} elseif ($firstBytes[0] -eq 255 -and $firstBytes[1] -eq 254) {
    $encoding = "Unicode"
}

echo $encoding

Open in new window

Replace "X:\your\path\file.csv" with your actual file.

The script will read the first 3 bytes from the file and output the encoding.

HTH,
Dan
0
 
25112Author Commented:
nice, thank you! :)
0
 
Dan CraciunIT ConsultantCommented:
Glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now