You have to be aware that using strings this way is always going to be somewhat 
inefficient, since each replace call will make a copy!

Of those especially in the following:
    
    
    f2.writeLine(sLine.replace(sFind, sReplaced.replace("\"", "")))
    
    
    Run

the sReplaced.replace("", "") seems unnecessary. Why not perform the 
replacement when defining sReplaced above? Since it doesn't seem to depend on 
the current line, it's going to be the same either way.

Also, as far as I can tell, the whole find seems unnecessary too. If replace 
cannot find the string sFind no replacement will take place. So you can just 
replace: 
    
    
    if sLine.find(sFind) > -1:
      f2.writeLine(sLine.replace(sFind, sReplaced.replace("\"", "")))
    else:
      f2.writeLine(sLine)
    
    
    Run

by
    
    
    f2.writeLine(sLine.replace(sFind, sReplaced)) # with `sReplaced` changed as 
above
    
    
    Run

Especially given that the substring seems to be found in 1/4 of the cases, I 
imagine this should be faster. The little overhead of replace over find 
shouldn't matter in that case.

To be fair, both things also apply to the Python code. 

Reply via email to