9 Replies - 353 Views - Last Post: 01 June 2012 - 05:18 PM Rate Topic: -----

#1 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Text search with changing variables

Posted 31 May 2012 - 09:56 AM

I am trying to search a text file where the line I'm searching for can change at any time with out notice. I have tried "Indexof" and "data.contains" to no avail, any suggestions? Below is an example Im looking for where inside the parentheses can change characters and the number of characters.

"DISP(XXXXXXXX) A830"
Is This A Good Question/Topic? 0
  • +

Replies To: Text search with changing variables

#2 Kakerergodt  Icon User is offline

  • D.I.C Head

Reputation: 87
  • View blog
  • Posts: 201
  • Joined: 01-May 12

Re: Text search with changing variables

Posted 31 May 2012 - 10:09 AM

Not really sure what you want, is it something like:

while(true) //Keep reading through the document indefineatly looking for matching lines.
{
   <read line>
   if(line.indexOf("DISP(") != -1 && line.indexOf("A830") != -1)
       list.add(line);
 
  <if last line, reset scanner and start reading file over again>
}

This post has been edited by Kakerergodt: 31 May 2012 - 10:09 AM

Was This Post Helpful? 0
  • +
  • -

#3 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Text search with changing variables

Posted 31 May 2012 - 06:10 PM

Sorry I didnt explain my goal very well. I am a self taught novice to Java. I am using a boolean for the A830 in the text file but the problem is there can be several cases of A830. Every time it comes across A830 it gives a true boolean and that is sending multiple signals to the program. Below is the boolean and a sample of the text that I'm reading through.

"ASSAULT WITH TB MD830 AORDAE17:08:34 DISP FES01115 A830 Text: ASSAULT WITH TB A830 AORE"

  public boolean alertAmbo() {
		if (Amboalerted == false) {
			
			if (data.contains("A830")){
				Amboalerted = true;
				new EggTimer(45);
				return true;
			}
		}
		return false;
	}

This post has been edited by pgfdbug: 31 May 2012 - 06:12 PM

Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,535
  • Joined: 05-May 05

Re: Text search with changing variables

Posted 31 May 2012 - 07:20 PM

Use a regular expression:
Pattern p = Pattern.compile("DISP \\w+ A830");
See example.
Was This Post Helpful? 1
  • +
  • -

#5 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Text search with changing variables

Posted 01 June 2012 - 07:12 AM

Thanks A million. It never even occurred to me to try a regex to match, well I didnt even know you could use regex to function as a search tool. Thank you again for the direction to head.
Was This Post Helpful? 0
  • +
  • -

#6 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Text search with changing variables

Posted 01 June 2012 - 04:20 PM

I wrote a boolean using the regex but it will not return true. Can anyone tell me what Im doing wrong?

  public boolean alertAmbo() {
	if (Amboalerted == false) {
		Pattern a = Pattern.compile("DISP     (\\w{8}) A830");
		Matcher m = a.matcher(data);
            if(m.find()){
            	Amboalerted = true;
		new EggTimer(45);
		return true;
		}
	      }
	return false;
     }

Was This Post Helpful? 0
  • +
  • -

#7 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,535
  • Joined: 05-May 05

Re: Text search with changing variables

Posted 01 June 2012 - 04:28 PM

Post a few examples of the strings your trying to match against. You do realize that the white space in your regex requires that there be white space after 'DISP' in the string, right?
Was This Post Helpful? 0
  • +
  • -

#8 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Text search with changing variables

Posted 01 June 2012 - 04:44 PM

Below are the logs I am trying to read through data in a string. Bold and underlined is the target and there are five spaces in the logs but there are not five spaces below.


011-10-01 17:23:28,262 (Reciever.java:49) - 16:58:34 INFO CT21056 Text: Medical ProQA processing complete616:58:59 SELECT FES01115616:59:29
DISP (FES01115) A8306 Text: A SICK616:59:29 PRIM (FES01115) A8306
2011-10-01 17:23:28,262 (Reciever.java:51) - 5 old Female Conscious Breathing5 16:58:35 NOMORE CT210566
2011-10-01 17:23:28,272 (Reciever.java:92) - DATA: 16:58:34 INFO CT21056 Text: Medical ProQA processing

This post has been edited by pgfdbug: 01 June 2012 - 04:48 PM

Was This Post Helpful? 0
  • +
  • -

#9 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,535
  • Joined: 05-May 05

Re: Text search with changing variables

Posted 01 June 2012 - 05:01 PM

You haven't specified an exact format on which you want to match. Is there only 1 space character between 'DISP' and '(' or can there be many? Will there always be opening and close parens? Stuff like that. Here you go.
Was This Post Helpful? 0
  • +
  • -

#10 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Text search with changing variables

Posted 01 June 2012 - 05:18 PM

The format above is how it always will appear. Im not sure why its not putting the spaces in the text but there are always 5 spaces between the 'DISP' and '('.

Again thank you, at the minimum gives me an avenue to work off of.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1