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.

replace string into same line

chaudharypareshchaudharyparesh Members
edited November -1 in Sahi - Open Source
OS=Linux
Browser=firefox

i want to replace particular word with new value into same text file

My Text file like (test.txt)
Hello
How are u
now i want to replace "Hi " on the place of "Hello" in same file
i want out put like(test.txt)
Hi
How are u

In both case filename is same

Any idea
Thanks in advance

Comments

  • chaudharypareshchaudharyparesh Members
    edited March 2011
    i m using syntax like this
    var $fileContents = _readFile("text.txt");
    var $lines = $fileContents.replace(/Hello/g, 'hi').split("\n");
    but how to get output in test.txt file like
    Hi
    How are u
  • narayannarayan Administrators
    You have to write back the contents into the file.

    var $fileContents = _readFile("text.txt");
    var $modified = $fileContents.replace(/Hello/g, 'hi');
    _writeFile($modified, "text.txt", true);
  • Wow man it's works
    thank u thank u so much

    can i get document of sahi programming
  • narayannarayan Administrators
    Hi Paresh,

    Have a look at the links on the right side on http://sahi.co.in/w/sahi

    Regards,
    Narayan
Sign In or Register to comment.