18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

retrieve data from Notepad file(.txt file)

AdmirerAdmirer Members
edited November -1 in Sahi - Open Source
I have one scenario to retrieve test data from 1st line to end of line in ".txt" file. In this file having test data in each line and i have to get substring based on position and length.

ex: 020239913 1234 5000.00 2010071620100817
.
.
.

In the above example from starting postion (1st) to 10th position takes as "Loan No." - (i.e 10 characters),
next from 11th position to 18th position takes as "LoanID" - (i.e 8 characters),
next 19th position to 28th position takes UPB amount - (i.e 9 characters),
next 29th position to 36th position takes as LastPaymentDate - (i.e 8 characters),
next 37th position to 44th position takes as NextPaymentDate - (i.e 8 characters).

like this i need to split data.

How to retrieve data from ".txt" file and also how to get substring from a string? Could you please anybody give an idea about this?.

In SAHI, mentioned how to get the data from ".csv" but I thought, this different from ".txt" file.

Thanks in Advance
Tulasi

Comments

  • narayannarayan Administrators
    Hi Tulasi,

    You can read a file using _readFile(filePath);

    You can modify the code below for your use case.
    var $contents = _readFile("C:\\myfile.txt");
    var $lines = $contents.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split("\n");
    for (var $i=0; $i<$lines.length; $i++){
      var $line = $lines[$i];
      var $loanNo = $line.substring(0, 10);
      var $loanId = $line.substring(11, 18);
      // etc. ...
    }
    

    Regards,
    Narayan
  • Hi Narayan,

    I checked with whatever you had given code above. it was working fine.

    Thanks a lot once again for your quick responses for my requirements.

    Thanks & Regards,
    Tulasi
This discussion has been closed.