By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,509 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

searching file for string

P: n/a
Hi all,

I have a html file that i'm trying to get data from, i need to search for a
specific string/tag and read the text between it and the close tag.

the setout of the data is like
<td> information to read into string </td>
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
sent a lil early :)

the tags that i am going to match on only appear in the context that i
require, im just unsure of a method that'd search from a set location in the
file for a specific string and then return an offset where the next
occurrence is,

anyone know of a method that's do the job?

thanks in advance

Michael

"Michael" <tr***@bigpond.net.au> wrote in message
news:FZ******************@news-server.bigpond.net.au...
Hi all,

I have a html file that i'm trying to get data from, i need to search for a specific string/tag and read the text between it and the close tag.

the setout of the data is like
<td> information to read into string </td>

Jul 17 '05 #2

P: n/a
"Michael" <tr***@bigpond.net.au> wrote in message news:<g1******************@news-server.bigpond.net.au>...
sent a lil early :)

the tags that i am going to match on only appear in the context that i
require, im just unsure of a method that'd search from a set location in the
file for a specific string and then return an offset where the next
occurrence is,

anyone know of a method that's do the job?

thanks in advance

Michael

"Michael" <tr***@bigpond.net.au> wrote in message
news:FZ******************@news-server.bigpond.net.au...
Hi all,

I have a html file that i'm trying to get data from, i need to search for

a
specific string/tag and read the text between it and the close tag.

the setout of the data is like
<td> information to read into string </td>


Make the whole file into a single string:
Expand|Select|Wrap|Line Numbers
  1. try{
  2. FileInputStream fis = new FileInputStream(file);
  3. FileChannel fc = fis.getChannel();
  4. MappedByteBuffer mbf
  5. = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
  6. byte[] barray = new byte[(int)(fc.size())];
  7. mbf.get(barray);
  8. lines = new String(barray); //one big string
  9. }
  10.  
And do the regular expression search on the string.
_Mastering Regular Expression_, 2nd ed. from O'Reilly
is a good book.
Jul 17 '05 #3

P: n/a
thanks mate :)
"hiwa" <HG******@nifty.ne.jp> wrote in message
news:68**************************@posting.google.c om...
"Michael" <tr***@bigpond.net.au> wrote in message

news:<g1******************@news-server.bigpond.net.au>...
sent a lil early :)

the tags that i am going to match on only appear in the context that i
require, im just unsure of a method that'd search from a set location in the file for a specific string and then return an offset where the next
occurrence is,

anyone know of a method that's do the job?

thanks in advance

Michael

"Michael" <tr***@bigpond.net.au> wrote in message
news:FZ******************@news-server.bigpond.net.au...
Hi all,

I have a html file that i'm trying to get data from, i need to search
for a
specific string/tag and read the text between it and the close tag.

the setout of the data is like
<td> information to read into string </td>


Make the whole file into a single string:
Expand|Select|Wrap|Line Numbers
  1.      try{
  2.        FileInputStream fis = new FileInputStream(file);
  3.        FileChannel fc = fis.getChannel();
  4.        MappedByteBuffer mbf
  5.         = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
  6.        byte[] barray = new byte[(int)(fc.size())];
  7.        mbf.get(barray);
  8.        lines = new String(barray); //one big string
  9.      }
  10.  

And do the regular expression search on the string.
_Mastering Regular Expression_, 2nd ed. from O'Reilly
is a good book.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.