Forum Discussion

slaugier's avatar
slaugier
Occasional Contributor
6 years ago
Solved

Trouble to use aqString.Find in a if condition

Hello

 

I have a text file, I want to copy it to a new file.

I want to modify it by using aqString.Replace with some substrings found by aqString.Find.

But aqString.Find seems to find nothing.

At the end, I have the exact copy of my file.

 

Do you have any advice? 

 

count = 1;
while (foundFiles.HasNext()) { aqFile.Create(fHTMLFile); aFile=foundFiles.Next(); bFile = aqFile.OpenTextFile(aFile.Path, aqFile.faReadWrite, aqFile.ctUTF8); bFile.Cursor = 0; while(! bFile.IsEndOfFile()){ bLine = bFile.ReadLine(); if (aqString.Find(bLine, "data")) { aqString.Replace(bLine,"data", "data" + count) } if (aqString.Find(bLine, "idChart")) { aqString.Replace(bLine,"idChart", "idChart" + count) } if (aqString.Find(bLine, "chart")) { aqString.Replace(bLine,"chart", "chart" + count) } aqFile.WriteToTextFile(fHTMLFile, bLine, aqFile.ctUTF8); } bFile.Close(); count = count+1 ; }

Thank you !

 

 

  • Thank you! It helped me a lot! 

     

    And I had to correct this way to solve everything :

     

      if (aqString.Find(bLine, "data") != -1) 
       {               
       bLine = aqString.Replace(bLine,"data", "data" + count)               
       }              
      if (aqString.Find(bLine, "idChart") != -1) 
       {                
       bLine = aqString.Replace(bLine,"idChart", "idChart" + count)               
       }              
      if (aqString.Find(bLine, "chart") != -1)  
       {                
       bLine = aqString.Replace(bLine,"chart", "chart" + count)                
       } 

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    aqString.Find returns an integer value (see https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/find.html).  if statments need a boolean value to execute.  basically, you're saying if 2 then...  That doesn't exactly execute.

     

    Basically, all your if clauses add != -1... like so.

     

      if (aqString.Find(bLine, "data") != -1) 
       {               
       aqString.Replace(bLine,"data", "data" + count)               
       }              
      if (aqString.Find(bLine, "idChart") != -1) 
       {                
       aqString.Replace(bLine,"idChart", "idChart" + count)               
       }              
      if (aqString.Find(bLine, "chart") != -1)  
       {                
       aqString.Replace(bLine,"chart", "chart" + count)                
       }  
  • slaugier's avatar
    slaugier
    Occasional Contributor

    Thank you! It helped me a lot! 

     

    And I had to correct this way to solve everything :

     

      if (aqString.Find(bLine, "data") != -1) 
       {               
       bLine = aqString.Replace(bLine,"data", "data" + count)               
       }              
      if (aqString.Find(bLine, "idChart") != -1) 
       {                
       bLine = aqString.Replace(bLine,"idChart", "idChart" + count)               
       }              
      if (aqString.Find(bLine, "chart") != -1)  
       {                
       bLine = aqString.Replace(bLine,"chart", "chart" + count)                
       }