Re: Finding substring in character array
On Thu, 18 Sep 2008, Jussi Piitulainen wrote:
Hakan writes:
One of the classes in "my" application is responsible for reading
from, interpreting and writing to XML files. Until yesterday, I had
read the entire text from the file and created a String out of
it. Java's string handling operations come very handy.
The problem is that some of the original files are really
large. The runtime system reaches a state where it's dry of heap
space when allocating a String for that kind of text. It works with
a character array instead.
Now I lack access to the indexof method, finding the next
occurrence of a given pattern in a String instance. As this is a key
operation for identifying the right tag in the XML file, I need some
corresponding routine to find the spot where a certain sequence of
characters can be found in the char[] array. Is there such a
subroutine somewhere off the shelf? It doesn't seem to be
implemented in the java.util.Arrays package. Thanks in advance.
Consider java.nio and its CharBuffer, which at least implements
CharSequence and so can be searched for regexen:
Wouldn't it be trivial to write a CharSequence implementation that just
wrapped a char[]?
Ah, that's basically what CharBuffer.wrap does! Right, carry on!
tom
--
got EXPERTISE in BADASS BRAIN FREEZE