最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

encoding - Can we convert ANSI encoded CSV file to utf-8 encoded file with javascript? - Stack Overflow

programmeradmin5浏览0评论

I have been looking answer for this question for days. Actually, I need to upload the ansi encoded csv file to web service. The front end application reads the file encode it's content to base64 and send it to web service in json format. But when I try to read file with javascript, non-english unicodes just gets changed to something else.

Is there any way to read ansi encoded csv file in javascript and converting its encoding to utf-8?

With my research, I think is impossible. The file must be in UTF-8 itself.

Any suggestions would be great help.

I have been looking answer for this question for days. Actually, I need to upload the ansi encoded csv file to web service. The front end application reads the file encode it's content to base64 and send it to web service in json format. But when I try to read file with javascript, non-english unicodes just gets changed to something else.

Is there any way to read ansi encoded csv file in javascript and converting its encoding to utf-8?

With my research, I think is impossible. The file must be in UTF-8 itself.

Any suggestions would be great help.

Share Improve this question edited Jun 10, 2015 at 10:24 Kirill Slatin 6,1733 gold badges21 silver badges38 bronze badges asked Jun 10, 2015 at 5:00 Mani RaiMani Rai 7042 gold badges10 silver badges26 bronze badges 1
  • 1 You mean ISO 8859-1 or Windows CP1252? – FlavorScape Commented Jun 10, 2015 at 5:11
Add a ment  | 

1 Answer 1

Reset to default 5

I am sorry I misread you question at first. Your trouble es at the moment of reading the file. It is useless to try to convert the file after contents were ruined when trying to load in a wrong encoding. I came up with FileReader API in this fiddle inspired by this example and article on html5rocks

  var r = new FileReader();
  r.readAsText(f, 'windows-1252');

The only trouble I see here is there is no auto encoding detection. You need to know encoding before loading the file.

发布评论

评论列表(0)

  1. 暂无评论