I have a Java application that makes heavy use of a large file, to read, process and give through to SolrEmbeddedServer (http://lucene.apache.org/solr/).
One of the func
The general algorithm for String.replace
is a little complicated, but it shouldn't be that bad. Looking at the code, it is in fact implemented using regex so wont be fast - ick.
Obviously, you can write much faster code by iterating through character by character. Possibly working out the exact length first.
You might want to consider how characters outside of[ -~]
are handled. You might also want to use a library which has already implemented the functionality.