UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> GetUnicodeFileIntoArray    
' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
' Original submission by Walter Niesz
' June 8, 2011
' When dealing with unicode files, you cannot easily use the standard LINE INPUT method of the OPEN statement.
' This is particularly so when the End-Of-Line characters are not the standard CarriageReturn/LineFeed combinations.
' This routine will read in a unicode file and parse the lines of data into an array so that they can be easily manipulated.

Public Function GetUnicodeFileIntoArray(Filename As String, EndOfLineCharacters As String)

   ' returns a string array containing each row of data contained in the file
   ' example usage:
   '     MyArray = GetUnicodeFileIntoArray("C:\MyFile.txt", vbLf)
   ' this would indicate that LineFeed characters were used as End-Of-Line markers

   Dim Buffer As String
   Buffer = Space(FileLen(Filename))

   Open Filename For Binary Access Read As #1
   Get #1, , Buffer                                                'Place entire contents of file in Buffer
   Close #1
   Buffer = StrConv(Buffer, vbFromUnicode)                         'convert unicode text over to standard strings

   GetUnicodeFileIntoArray = Split(Buffer, EndOfLineCharacters)    'break apart the lines of data and insert them into an array

End Function

Creative Commons License
GetUnicodeFileIntoArray by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 3,412 times.  This page was last modified 14:15, 8 June 2011 by Walter Niesz.   Disclaimers