Hi,
I am trying to read a text file placed on the desktop using the following piece of code. Unfortunately, the text which is read is gibberish. Can someone please help me out how to read text files correctly.
And how to work the the content of the text file, like finding strings?
sPath ="C:\\Users\\INKKANAM\\Desktop\\API_Error.txt";
myFile = aqFile["OpenTextFile"](sPath, aqFile.faRead,aqFile.ctUnicode);
Log["Message"]("File read");
var sFile = myFile["ReadAll"]();
Log["Message"](sFile);
myFile["Close"]();
Output: See attached picture
Hi,
Just to double-check: are you sure that the file is really in Unicode format, but not in, say, UTF-8 one?
Hi,
Yes I changed the Unicode format.
Now that has been resolved, how to access the content of this file and search for a word within this file?
Hi,
The content of the file is in the sFile variable.
You may use methods provided by the aqString object (see help for details) or use regular expressions or any other means that works best for the given file content.
Open file in Notepad and save in unicode or whatever format you are using in TextCoding Type
aqFile.ctANSI | 20 | ANSI |
aqFile.ctUnicode | 21 | Unicode (UTF-16) |
aqFile.ctUTF8 | 22 | UTF8 |
2. for searching in particular line use
var myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode);
while(! myFile.IsEndOfFile())
{
s = myFile.ReadLine();
////use :aqstring.find
aqString.Find(InputString, SubString, StartPosition, CaseSensitive)
}
Thanks for your help, guys!
@komalak11, did these suggestions help you resolve the question? Please mark the best answer as a solution.
Subject | Author | Latest Post |
---|---|---|