Finding words in a line

I have the following code which searches the occurrence of 3 words in a line. If the three words are present in the line then the line is tokenized. Unfortunately it tokenizes a line which has an occurrence of at least one word and not all the 3 words. Any ideas on how to do this??
JTextField fst, lst, md;
fst = fields[0];
lst = fields[1];
md = fields[2];
try {
while ( (str = raf.readLine()) != null) {
int i = str.indexOf(fst.getText().trim());
int k = str.indexOf(lst.getText().trim());
int l = str.indexOf(md.getText().trim());
if((i < 0) && (k < 0) && (l < 0)){
str = raf.readLine();
else {
StringTokenizer st = new StringTokenizer(str, "\t");
while (st.hasMoreElements()) {
msgout.append(st.nextToken() + "\n");
break;

>
if((i < 0) && (k < 0) && (l < 0)){
str = raf.readLine();
}This will trigger if the line has none of the words, so if the line has even one, the else will work. You probably want to use or ('||') so that if the line is missing even one of the words the above the will trigger

Similar Messages

  • Finding Words with more than Two Vowels (Regex)

    Hello all, I've been working on this for quite some time now.  I need to use a regular expression to find words that contain more than two vowels.  I am getting stuck.
    Here is what I have so far.  I am using emacs to find them in a text file.
    I use C-M-s and the expression /<[^aeiou]*[aeiou][^aeiou]/>
    It finds words with one vowel, but I need to find if it has more than two, and I'm not sure how to go about doing that.
    Any help is appreciated!

    alphaniner wrote:
    This better not be a homework question...
    [aeiou].*[aeiou].*[aeiou]
    or, more succinctly (I think...)
    \([aeiou].*\)\{3\}
    I tested it with grep on a file with one word per line.  Seems to work in that context.  More than one word per line and it breaks.  I know nothing of emacs or your data, so I have no idea if it will suffice.
    I'd also suggest you go back over your expression and put into words exactly what you think it is doing.  I'm no regex expert, but it doesn't seem at all fit for what you're trying to do.
    Thanks that seemed to work!

  • Find words within a text file

    Hey all.
    I am playing around with the idea of finding a line of text within a text file, by using scanner and some next methods.
    The way I am trying to get it to work is that one enters a string and the program then finds all the lines of text containing that
    user-entered string and then prints them.
    The text file in question contains names of University papers and their room numbers, quantity of students etc.
    Example:
    IBUS212     EALT006     1am     72     AL     LI     
    BMSC241     MCLT102     2     pm     8     AL     COOREY     
    My problem annoyingly enough seems to be that I can't think how one could compare the string entered to the lines of text being
    scanned in the text file.
    My latest go involved what you see in the code, scanning the examdata.txt file for a user-entered course number, using course.next();
    by going with the example above it would be IBUS212. The task was to then to find all of the lines containing that number and print them out using
    println (what I have tried with id and line) as well as the rest of that line eg: EALT006     1am     72     AL     LI .
       public void printCourse()
        try
            String details, input, id, line;
            int count;
            Scanner user = new Scanner(System.in);
            System.out.println();
            System.out.println();
            System.out.println("Please enter your course ID: ");
            input = user.nextLine();
            Scanner course = new Scanner(new File("examdata.txt"));
            course.next();
            course.nextLine();
            id = course.next();
            line = course.nextLine();
            if(input.equals(id))
                System.out.println("Your course times are: "  + id + "and" + line);
            else
              System.out.println("Your course does not exist."); 
            catch(IOException e)
                System.out.print("File failure");
      }Any advice/help/troubleshooting would be greatly appreciated.
    Edited by: AUAN on Aug 13, 2009 9:43 AM
    Edited by: AUAN on Aug 13, 2009 9:44 AM
    Edited by: AUAN on Aug 13, 2009 9:49 AM

    You'll want [to loop while|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html] the course Scanner has a next line and then print the line if it contains the entered text.
    For useful methods you can check the Javadoc of String and Scanner (use your browser search on keywords like 'next' or 'contains' to find them).

  • How do you find the number of lines in a file?

    I need to count how many lines there are in a file, I am using a BufferedReader to read in the data, but how can I find the number of lines?
    Thanks

    That depends. How do you define a line? Is it a specific number of
    characters, a String that's terminated by a newline character or some
    combination thereof?

  • Read the first word of each line in a text file

    i need to read the first word of each line of a text file.
    i know of line.split() but not actually sure how i would go about using it
    Any help most appreciated
    Many Thanks
    Ben

    Hi thanks for the reply!
    this is what i tried... and it still doesn't get me the first word of each line!
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.io.*;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import java.util.Calendar;
    import java.util.Scanner;
    import java.util.Vector;
    import java.text.SimpleDateFormat;
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    import java.io.BufferedReader;
    public class testing {
         Vector progs=new Vector();
         Vector rand=new Vector();
         String[] tmp = new String [2];
         String str;
         String str2="ewerwer";
         String str3;
         public void programTest()
                   try
                             BufferedReader in = new BufferedReader(new FileReader("progList.log"));
                             while ((str = in.readLine()) != null)
                                  progs.add(str);
                        catch(IOException e)
                             System.out.println("cannot read file");
         //////THE ISSUES IS HERE....I WANT TO GET THE FIRST WORD FROM EACH LINE OF THE FILE!!!     
              try
                             BufferedReader in2 = new BufferedReader(new FileReader("eventLog.log"));
                             while ((str = in2.readLine()) != null)
                                  tmp = str.split(" ");
                                  System.out.println(tmp[0]);
                        catch(IOException e)
                             System.out.println("cannot read file");
    public static void main(String[] args)
                 testing B = new testing();
                 B.programTest();
               //  B.fileToVector();
                 //B.LoginWindow();
               //B.anomDetect();
    }//end class

  • Program to read only specific words in each Line in a text file

    Hi
    I have a question
    I need to write a program where the program must read only specific words in each line
    I will give you an example...
    PSAPPSRV.21201      1-42 13.35.54 238.360 Cur#1.HDEV RC=0 Dur=0.000 COM Stmt=SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = 'SYS'
    PSAPPSRV.21201      1-43 13.35.54 0.040 Cur#2.HDEV RC=0 Dur=0.000 COM Stmt=SELECT STYLESHEETNAME FROM PSOPTIONS
    These are two lines in my text file...now I need to read only the SQL statements present that is both SELECT statements.. Can you please suggest a method.......

    My first reaction to the question is why would you want such thing, but may be I am unknown :)
    Assuming you have the text as string, I mean
    String str = "PSAPPSRV.21201 1-42 13.35.54 238.360 Cur#1.HDEV RC=0 Dur=0.000 COM Stmt=SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = \'SYS\'";you can obtain the sql statement using substring method like
    String result = str.substring(str.indexOf("SELECT")); Again I assume there is no word SELECT preceding and the word SELECT is all caps.

  • How to determine the position of a word in a line

    hello
    i want to know the position of a word on which caret is at present or the position of the selected word in a line displayed in the JEditorPane. for example, if this line is displayed
    Java is an Object oriented Language.
    if i select "an" then its position i get must be 3. Select Java postion must be 1 and so on.
    thanx in advance
    -Ashish

    Hi,
    you can use a StringTokenizer to break the result of getText() of JEditorPane into words and simply count them until the caret postion is passed. Add a method like this in your JEditorPane subclass:
    public int whichWord() {
    String delimiters = "\n\t "; // checking for new line, tab and space as word breaks
    StringTokenizer st = new StringTokenizer(getText(),delimiters,true);
    int pos = getCaretPosition();
    int count = 0;
    int len = 0;
    while ((len<pos)&st.hasMoreTokens())
    String s = st.nextToken();
    len += s.length();
    if (delimiters.indexOf(s)==-1) { count++; }
    return count;
    }Hope this helps - not tested, coded on the fly into this textbox.
    greetings Marsian

  • MS Word 2007 table lines have interesction tick marks

    Hello,
    MS Word 2007 SP2
    Adobe Acrobat 9.0.0 Plus
    A table created in Word, where row lines are shown but not column lines, shows on some lines tick-marks where row and colums would intersect. In AA version 7 this was not an issue, however, when converting from within Word this too was an issue.
    The image below didn't turn out as clear here than the original, but you still can see the Word bit left and AA on the right with the tick-marks.
    How can it be avoided?
    Thank you
    Stefan

    I'm experiencing this myself. I found instructions to navigate to Edit > Preferences > Page Display. Then, uncheck 'Enhance Thin Lines'. This lightens the lines considerably; reducing the very dark, chunky lines. However, table lines are still not the same width/thickness regardless of the zoom level in Acrobat (50% - 800%). And there is no pattern to where thicker lines appear; header rows, odd rows, etc. A random mess. I'm 100% positive the lines are set properly in Word 2007. And interestingly, all tables lines display equal widths consistently in printed copy- when printing from the PDF. The issue seems to be Adobe's electronic page display and that the 'solution' I found does not work. I have the latest version of Acrobat Pro and a colleague has the latest version of the Reader without a writer license-- no conflict of versions or software suite.
    I deliver documentation to customers electronically. My documents have many tables. My deliverables to look unprofessional and unpolished. My deadlines haven't been met due to research and this unresolved issue. Difficult to accept.
    So frustrated!  Please help!
    Jennifer

  • Select first word in each line of a text file to do something.

    How do I select the first word in each line to do something newer from a text file in Powershell?
    Example:
     GBL                            Primary    File            
     local                          Primary    File            
     localhost                      Primary    File            
     Opstest                        Primary    File            
     TrustAnchors                   Primary    File            
    99upgrade

    Hi 99,
    here's an example on how to do it:
    $lines = Get-Content "C:\ExampleFolder\Example.txt"
    foreach ($line in $lines)
    Write-Host ($line.Split(" "))[0]
    Just replace the Write-Host line in the loop with what you actually want to do with the first word in the line.
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Hi-In Script Editor how can we maintan gap between words in one line

    Hi,
    Can any body help on how to maintain gap between words in same line?
    Thanks in advance

    Hi,
    is it a Hard-coded text or a variable text.
    If its a constant & Hard coded text then u can directly maintain by using space bar.
    if its a variable text just define a paragraph format with Tab positions as per ur requirement of space..
    Hope it helps!!
    Rgds,
    Pavan

  • Comparing two words in different lines

    hi frens, please help me.
    let say each line has 2 words
    <word1> <word2>
    what i am going to do is to compare the first word for each line. for example, let say this is the input file:
    hello world
    baby good
    hello baby
    good stuff
    hello good
    good job
    what i want for the output is:
    hello = world; baby; good
    baby = good
    good = stuff; job
    so it compares the prefix, if equals, then just print the second words behind. they are stored in hash table. thanks.

    Cross-posted,
    http://forum.java.sun.com/thread.jsp?forum=31&thread=411889&tstart=0&trange=15

  • Script to find word stacks in InDesign

    CS6, InDesign -- I've been looking for a proofing script that finds word & letter stacks and highlights items found & would be easily removed once items have been reconciled.

    While this scripting forum is a great place to get scripting help, it's also very easy to misuse it. Please bear in mind that for most (if not all) of the participants here, writing scripts is a source of income. If someone writes a particularly useful script, don't be shy to offer money (privately)! Also, please do not expect that complete scripts will be written for you (although in many cases they will be). If you are a novice scripter and show an interest in learning, you will generally find that the help you recieve will be much more positive.
    Here's a short list of "Dos" and "Don'ts" to keep in mind...
    Do ask for help in automating your work in InDesign, but Don't expect a full solution for free.
    Do show an interest in learning, and people will probably try to help you, butDon't ask for other people to solve all your problems for you.
    If you need a script written for you, Do ask if someone is available to write one for pay, but Don't keep such an issue on the forum. Work it out off the forum please.
    Please Do thank others who spend the  time to solve your issues, and pleaseDon't expect every issue to be solved on a public forum. Many solutions have  taken a lot of programming time to work out, and it's not reasonable to  expect such solutions to be given away for free.
    Please Do give code examples to help other people, but please Don't pass off others code as you own!
    Please Do make a note in the topic of a new thread of what language you are using as well as the version number that you are using such as: [JS][CS3].
    Please Don't branch off a discussion in the middle to a new topic -- please start a new one!
    Please Don't start two discussions on one topic -- it makes it very confusing!

  • Search third word of all lines in a file

    I need to search the third word of all lines in a text file.
    Also,if the word is found, the total number of times the word appears should be counted.
    Is that possible?

    try looking up "split" or "stringTokenizer" in the java api these methods split up strings
    to compare string remember you cant use "=="
    if you get stuck show us what you tried and well be more than happy to help

  • How do I locate non picture files and location? I'm getting low memory and can't find word,PDF etc

    how do I locate non picture files and location? I'm getting low memory and can't find word,PDF etc

    iPads don't have a filesystem like a computer, Files of that nature must be associated with an App and reside inside that particular App's file space.  So the way to find them is to open the App that opens that file type and look in its file or document list for them.

  • How do i find words, excel and power point in my mac book air ?

    how do i find words, excel and power point in my mac book air ?

    You would have to purchase, install, and update them first.
    They would be installed into /Applications, probably into an MS Office folder. The installer may have placed aliased copies of the icons in your Dock, or if not, use the Finder > Go menu > Applications, and have a look around. When you find the applications, you can drag/drop the principal three onto your Dock — where a single click can launch them.

Maybe you are looking for

  • Macbook 2006 won't let me pass the black screen.

    I have a macbook 2006 i had recently change the hard rive and also the battery because it would turn on and it crash my hard rive now that i want to start up the macbook all i get is a white solid light and it has no sound or any beeps i tried on hol

  • How do I add a new email account?

    I installed Thunderbird today and have no email accounts set up yet. That is because by following the instructions in the help files, I was lead straight into a brick wall. I can't find a way to insert a screenshot of the help page. It says to: First

  • Windows 8.1 and Photoshop cc

    Updated to windows 8.1 on Dec 19th.  Now my photoshop cc is sluggish and fails to keep display current with activity being processed. I attempted to restore my computer back to Windows 8 however can only go back to installation of windows 8.1 on Dec

  • Exporting to .MOV works sometimes and not others? Help?

    I've been working on an animation project, but I'm really new at this. I need to export my different clips as .mov files. Sometimes, this works great. But most of the time, the .mov exports as a still image (the first frame of my clip). When I export

  • Graphical message mapping examples for JDBC and RFC lookup

    hi, can any body provide me graphical message mapping examples for the "JDBC Lookup" function and "RFC Lookup" function? I'm now studying the graphical message mapping and want to try those 2 functions. thank you. I expect the examples to be simple e