|
-
Feb 25th, 2015, 06:56 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] ADODB.Stream auto-detect charset problem
Sorry, I'm bit annoying with this threads but I wouldn't ask if I'm able to solve that by myself... :/
I have a problem now with reading files that are in different encodings. I have found a pretty simple solution with ADODB.Stream object, but the problem is that it doesn't work good with detecting between ANSI/UTF-8 and Unicode charsets.
Module code:
VB Code:
Private Sub Main() With CreateObject("ADODB.Stream") .Open .LoadFromFile "1.txt" MsgBox .ReadText End With End Sub Function MsgBox(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String) As VbMsgBoxResult MsgBox = CreateObject("WScript.Shell").Popup(Prompt, 0&, Title, Buttons) End Function
File "1.txt", Unicode: Сампле тест - or if ANSI: Sample test
The above example works if the file is saved in Unicode, but when I save "1.txt" in UTF-8 or ANSI, the result from ADODB.Stream will be corrupted. It appears that I need to manually specify charset type in the stream if it isn't Unicode (I have also tried to put .Charset = "_autodetect" but it won't work), so how to do that automatically since I don't know which file will be loaded (it depends on user)? Also, I have read that in some cases BOM doesn't exist in the file but nevertheless programs like Notepad read that files correctly.
Last edited by MikiSoft; Feb 25th, 2015 at 07:03 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|