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"
Text search with changing variables
Page 1 of 19 Replies - 254 Views - Last Post: 01 June 2012 - 05:18 PM
Replies To: Text search with changing variables
#2
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
#3
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"
"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
#4
Re: Text search with changing variables
Posted 31 May 2012 - 07:20 PM
#5
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.
#6
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;
}
#7
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?
#8
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
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
#10
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.
Again thank you, at the minimum gives me an avenue to work off of.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|