I have a folder with text files that contains Japanese data (utf-8 text file). I have to search a specific string in those files and find the match. once the match is found I have to copy complete line and its line number (single file can have multiple match). The issue is we can't read UTF-8 data using FSO hence to use ADO stream. I don't know how to read the text file line by line to use .readline
and how to use search function like InStr(pos, s, FindThis, vbTextCompare)
which we use with FSO
Sub TestR_utf_8()
Dim st As ADODB.Stream
Dim sPathname As String, sText As String
sPathname = "c:\tmp\test_utf-8.txt"
' create a stream object
Set st = New ADODB.Stream
' set properties
st.Charset = "utf-8"
st.Type = adTypeText
' open the stream object and load the text
st.Open
st.LoadFromFile (sPathname)
' read 10 characters
sText = st.ReadText
' display the characters read
MsgBox sText
st.Close
Set st = Nothing
End Sub