1. Collect information about the issue (mainly using Google)
2. Analyze information and design solution
3. Implement solution
So I found another COM-object which can be used reading files which seems to manage most of the Char Sets I normally deal with: Adodb.Stream
The result (getFileContent.vbs):
Function getTextFileContent (strFileName, strCharSet)
Const adTypeBinary = 1 'not used
Const adTypeText = 2
'Set default CharSet
If strCharSet = "" Then strCharSet = "ASCII"
' *** CharSets ***
' Windows-1252
' Windows-1257
' UTF-16
' UTF-8
' UTF-7
' ASCII
' X-ANSI
' iso-8859-2
Set objStreamFile = CreateObject("Adodb.Stream")
With objStreamFile
.CharSet = strCharSet
.Type= adTypeText
.Open
.LoadFromFile strFileName
getTextFileContent = .readText
.Close
End With
Set objStreamFile = Nothing
End Function
8 comments:
Thank you! Checked a bunch of solutions and only yours helped.
Thanks a lot
This really helped me a lot !
Good to hear :-)
/Stefan
Thank you very much. It was really helpful and I was unable to find a good examples on the web.
Thank you very much. It was really helpful and I was unable to find a good examples on the web.
Apparently still one of the better solutions! I only have one problem left: how can I put a html-break at the end of every line. I tried several possibilities but none works :-(
Any suggestions?
What are you trying to do?
Check out: http://www.w3schools.com/ado/met_stream_readtext.asp
In ASP I try to read a txt-file. With .readText I lose the lay-out of my text. So after "soutenue." I want a 'break' (see example):
«Robe soutenue.
Un Saint-Estèphe de bon niveau, à attendre quelques années.»
resultitel=getTextFileContent(titeltext,char)
Function getTextFileContent(strFileName, strCharSet)
Const adTypeBinary = 1 'not used
Const adTypeText = 2
'Set default CharSet
If strCharSet = "" Then strCharSet = "Windows-1252"
Set objStreamFile = CreateObject("Adodb.Stream")
With objStreamFile
.CharSet = strCharSet
.Type= adTypeText
.Open
.LoadFromFile strFileName
Do Until objStreamFile.EOS
getTextFileContent = .readText(adReadLine)
Loop
.Close
End With
Post a Comment