Forum Discussion

SangeetNenwani's avatar
SangeetNenwani
Contributor
3 years ago
Solved

open file in hex format

I want to read and edit a file. If one open that file normally it has stranger characters. But if with use of Notepad++ and hex view, its readable. Now I want to read the file in testcomplete and e...
  • SangeetNenwani's avatar
    SangeetNenwani
    3 years ago

    I have found another solution. Writing here if someone needs this thing in future.

     

    //open as binary file

    var binFile = aqFile["OpenBinaryFile"](stringFilePathBinFile, aqFile["faReadWrite"]);

    // Reads bytes from the file
    readBytesFromBin = binFile["ReadBytes"]();

    // Obtains the number of items in the array returned by ReadBytes()
    countBytes = readBytesFromBin["Count"];
    for (var i = 0; i < countBytes; i++)
    {
    // Obtains the current item
    var byteValue = readBytesFromBin["Item"](i);

    //convert it to ascii code and store it in string
     var stringBinFile =stringBinFile+ aqConvert["VarToStr"](aqString["Format"]("%c", aqConvert["VarToInt"](byteValue)));
    }