Replace a string in each line with strings in array

Replace a string in each line with strings in array

1
NewbieNewbie
1

    Jun 25, 2015#1

    Hi!

    How to replace a string in my document with a list of values in an array?

    For example for Hello:

    Code: Select all

    dasfasfasfHello Worlddfhhd
    fghfjuj Hello USAfgdgfg
    asdasd Hello ITALY agfg
    asdfHello Francehjm
    asdHello Chinahdg
    var array = ["Heil","BYE","CIAO","Salut",...]

    I want this result:

    Code: Select all

    dasfasfasf Heil Worlddfhhd
    fghfjuj BYE USAfgdgfg
    asdasd CIAO ITALY agfg
    asdf Salut Francehjm
    .
    .
    .
    I'm trying to do this with this code, but I don't know how to read a line:

    Code: Select all

    function myReplace() {
    	var array= [“Heil”,”BYE”,”CIAO”,”Salut”];
    	UltraEdit.activeDocument.top();
    	
    	for (var nVariable = 0; nVariable < 10; nVariable++){   // How to insert length of document?
    		var s=UltraEdit.activeDocument.selectLine();
    		var t=array[nVariable];
    		s.findReplace.replace("1", t);  // how i can do here? 
    	}
      
      UltraEdit.outputWindow.write("as");
    }
    myReplace();
    Thanks for help guys.

    6,602548
    Grand MasterGrand Master
    6,602548

      Jun 26, 2015#2

      Here is a script which works without comments as I'm in hurry at the moment.

      Code: Select all

      function myReplace()
      {
         var asWords = ["Heil","BYE","CIAO","Salut"];
      
         UltraEdit.ueReOn();
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=false;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=false;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.searchInColumn=false;
         UltraEdit.activeDocument.findReplace.preserveCase=false;
         UltraEdit.activeDocument.findReplace.replaceAll=false;
         UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
      
         for(var nWordIndex = 0; nWordIndex < asWords.length; nWordIndex++)
         {
            if(!UltraEdit.activeDocument.findReplace.replace("Hello",asWords[nWordIndex])) break;
         }
      }
      
      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Define environment for this script.
         UltraEdit.insertMode();
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
      
         // Move caret to top of the active file.
         UltraEdit.activeDocument.top();
         myReplace();
      }
      
      Best regards from an UC/UE/UES for Windows user from Austria