473,385 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

searching file for string

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
3 8360
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hivie | last post by:
I have a problem that is causing me problems. I have a text file that stores 5 lines of crap (stuff that I dont need( for the user only)). After that there is data that is in three columns...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
1
by: Bud Dean | last post by:
I need to search files for given text. In particular, I'm searching dll's, exe's, asp, aspx and html pages. I am having difficulty converting the byte arrays to strings. The following code...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
2
by: angus | last post by:
hello everybody, i'm having some problems searching a text file and then deleting the line. since i used fileopen(), i can use the eof() function to loop through the file, searching for the...
7
by: pbd22 | last post by:
Hi. I am somewhat new to this and would like some advice. I want to search my xml file using "keyword" search and return results based on "proximity matching" - in other words, since the search...
1
by: warheart | last post by:
hi im kinda new to programming i aint lazy to search and learn :D but i am getting despirate... ive been looking everywhere for a code to search a txt file and find a string, and then give...
4
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given...
6
by: bushwacker | last post by:
Hello all, I'm a chemical engineering student. our teacher has given us a project to do some calculations based on some equations. those equations include constants, which are to be read from a...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.