Jump to content

String Replace in file..is array necessary?


Recommended Posts

Hi,

I'm attempting a recursive string replace in files. Most examples I've found read the file to an array and then step through each line performing the replace. It works like a champ, however, somewhere I saw an example where functions were being parsed from a file directly from the fileread (using RegExp). In other words, the entire file was treated as a single string. Does anybody know of any replace examples using that method? Any pros or cons?

Thanks for reading, and for any advice.

Link to comment
Share on other sites

A pro is definately the speed. StringRegExp is much faster than reading from an array. It also doesn't use loops or anything like that. A con may be it is a bit difficult to read if you aren't well versed with StringRegExp (at least in my opinion). A simple comment next to the line would fix that though.

Personally, I like StringRegExp a lot more than arrays.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...