I want to find a particular word in a file

Hi,
I have got the contents of a file in a ArrayList using :
String name = null;
     ArrayList<String> myArrayStrings = new ArrayList<String>();Then got a word using : myArrayStrings.get(r) This word was generated randomly and in a loop so I dont know what this word is going to be.
Now I want to search this "myArrayStrings.get(r)" in another file. How to do that?
Thanks

Now I want to search this "myArrayStrings.get(r)" in another file. How to do that?Store the returned String. Do the same thing you did to read the first file to read the second file (i.e. read it in line-by-line and store the lines in a list). Then check if that list contains the String you stored from the first list.
E.g. (using your code):
String name = myArrayStrings.get(r); // assuming r is initialized somewhere before this
if ( otherList.contains( name ) ) { // assuming otherList is your second list
    // do something
}

Similar Messages

  • How to find a particular word in a file using java

    Program how to find a particular word in a file

    SirivaniG wrote:
    Program how to find a particular word in a fileOkay, I finished it. Now what?

  • How to find a particular word in a textArea

    can anyone tell me how to search for a particular words in a textArea that contains hundreds of sentences by ignoring the space. for example i want to search for the word "book"
    so far i can detect the words with the space included
    if the sentence goes like this
    "hello_this_isMy book" the searched words can be found
    but if the sentece goes like this
    "Hello_this_isMy_booK " the searched words can not be found
    .. can anyone pls tell me how to do this.

    I though you didn't WANT it to be found, your original post isn't clear
    public boolean searchWord(String text, String word){
       boolean wordFound = false; 
       StringTokenizer stkn = new StringTokenizer(text," ");
       while(stkn.hasMoreTokens() ){
          String tmp = stkn.nextToken;
          if(tmp.equals(word)) wordFound = true;
       stkn = new StringTokenizer(text,???);   // fill in the -???- yourself
       while(stkn.hasMoreTokens() ){
          String tmp = stkn.nextToken;
          if(tmp.equals(word)) wordFound = true;
       return wordFound;
    }

  • How to use GREP to find one particular word with automatic hyphen?

    I know I have in my text a word with automatic hyphen on the end of line, say Wo-rd.
    How can I find it?
    Thanks.

    I think you might do better to edit the hyphenation in the Dictionary.
    One reason words hyphenate incorrectly is the wrong language has been applied. Both spell checking and hyphenation rules are governed by the language selected for the text, and language is a character-level attribute so that you can select inidvidual words and assign a different language to them if you like.
    If that's the probelm here, you can look for the word using find/change (without worying about the hyphen) and change the language for all instances.
    In either case you will be far better off fixing the problem on a global scale in the document than you will be finding a particular instance of that word at the end of a line. Any editing you do in the future may cause the problem to reappear somewhere else.

  • How read a particular word in a file using java

    Hi.. friends
    I have one problem with reading contents of a file.
    can u give me the source code
    how to read a data from file
    example.
    ss.txt this file contains following data..
    Another Important thing to remember is that the
    instance variables are created and initialzied.
    now the thing is
    i wanted to find words like.. remember, instance
    from ss.txt
    please help me.
    Thnx..

    Read a data from file:
    public void getFileContents() throws Exception
            BufferedReader rdr =
                    new BufferedReader(
                    new InputStreamReader(
                    new FileInputStream(xmlFileName)));
            System.out.println("Reading from file....:" + xmlFileName);
            StringBuffer contents = new StringBuffer();
            String line = null;
            while((line = rdr.readLine())!= null)
                contents.append(line);
        }

  • Finding a Particular string in a Database in the most Optimized way

     Hi All,
              Below is the query to find  a Particular String in the entire database tables,I have a Database of about 500 + tables and each contains many data's .In these tables i want to find a particular
    string but didn't know the column name and table name.so i did as below,but for executing this it almost take 40 - 45 minutes.Is there any other way to Optimize this and make the Query execution Faster.I am copying the code below.Please comment
    DECLARE
        @search_string  VARCHAR(100),
        @table_name     SYSNAME,
        @table_id       INT,
        @column_name    SYSNAME,
        @sql_string     VARCHAR(2000),
     @TableCount    INT,
     @ColumnCount   INT
    SET @search_string = 'Developer'
    DECLARE   @Tables TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
    DECLARE   @Columns TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
    INSERT INTO @Tables
    SELECT name, object_id FROM sys.objects WHERE type = 'U'
    SELECT @TableCount=COUNT(1) FROM @Tables
    WHILE (@TableCount >0)
    BEGIN
      SELECT TOP(1)
         @table_name=name
        ,@table_id=id
      FROM  @Tables ORDER BY Rownumber
    INSERT INTO @Columns
    SELECT name,object_id FROM sys.columns WHERE object_id = @table_id AND system_type_id IN (167, 175, 231, 239)
    SELECT @ColumnCount=COUNT(1) FROM @Columns
      WHILE (@ColumnCount >0)
      BEGIN
        SELECT TOP(1)
           @column_name=name
        FROM  @Columns
        WHERE id= @table_id
         ORDER BY Rownumber
         --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''%' + @search_string + '%'') PRINT ''' + @table_name + ', ' + @column_name + ''''
          SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''' + @search_string + '%'') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
    + ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
         --select (@sql_string);
          --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] = ''' + @search_string + ''') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
    + ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
         EXECUTE(@sql_string)
       SET @ColumnCount=@ColumnCount-1
       DELETE FROM @Columns WHERE  Name =   @Column_Name
      END
    SET @TableCount=@TableCount-1
    DELETE FROM @Tables WHERE Name= @Table_Name
    END

    You may also try the below :
    http://gallery.technet.microsoft.com/c0c57332-8624-48c0-b4c3-5b31fe641c58

  • How to extract unique words in all files

    Hi,
    I am trying to extract all the UNIQUE words of all the files in a directory. well it gives me all the words but along with that all the single letters(alphabets and also repetitions of the same ) and also the output is not unique. I dont want the alphabets only unique words in the files. [Like for example if I encounter file x with words "cat mat sat" and then file y with words "cat mat bat pat". My output should be "cat mat sat bat pat"]
    Can you please let me know what is used to get the unique words only? Or how I can modify my code to get the desired output...
    //String input = "Input text, with words, punctuation, etc. Well, it's rather short.";
                   Pattern p = Pattern.compile("[\\w']+",Pattern.MULTILINE);
                   FileInputStream fis = new FileInputStream(file);
                 FileChannel fc = fis.getChannel();
                 ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, (int)fc.size());
                 Charset cs = Charset.forName("8859_1");
                 CharsetDecoder cd = cs.newDecoder();
                 CharBuffer cb = cd.decode(bb);
                 // Run some matches
                 Matcher m = p.matcher(cb);
                   while ( m.find() ) {
                       //System.out.println(cb.substring(m.start(), m.end()));
                       System.out.println(m.group());
                    Thanks

    Can you tell me how to add the contents of a file into a set?
       import java.io.*;
    import java.util.*;
    public class RmDup{
         public static void main(String args[]){
                   FileReader fr = new FileReader("Dups.txt");
                   BufferedReader br = new BufferedReader(fr);
                   String s1[]=br.readLine();
                   String s2;
                   while ((s2=br.readLine())!=null){
                    HashSet ref = new HashSet( s1 ); // create a HashSet
                    Iterator i = ref.iterator(); // get iterator
                    System.out.println( "\nNonduplicates are: " );
                    while ( i.hasNext() )
                         System.out.print( i.next() + " " );
                    System.out.println();
    }I am trying using this: but getting errors 1: incompatible types and 2:cannot find symbol constructor HashSet(java.lang.String[]).
    Thanks

  • Grep to find first occurrence of a particular word in a story

    Hello Grepers
    I haven't had luck working out a Grep to find first / last occurrence of a particular word in a story.
    To find the first occurrence of the word hello in a paragraph I would use this grep.
    (Hello(?!=Hello*$))
    For the last this works.
    ((?=Hello(?=.*Hello)))|(Hello(?!=Hello*$))
    I have tried single line and multiline prefixes but they don't do the trick.
    Waiting in suspence,
    Trevor

    Hi Marc,
    Thanks for your reply, I'm glad you got my subtle hints.
    1) First Hello in the paragraph(s)
    Marc Autret wrote:
    Also, it seems to me that the GREP patterns you've posted are wrong and only work by accident. For example:
    (Hello(?!=Hello*$))
    actually means: find 'Hello' if and only if the match is not followed by '=Hell' and 'o' zero or more times and an EOL.
    Well Marc I made a Hell of a mistake!!!
    I meant to write (Hello(?!=Hello.*$)) with a dot there which at least is not quite as stupid if not more correct.
    In fact both (Hello(?!=$)) without a . and Hello(?!=^) work, well sort of work for the first Hello of the paragraph(s) depending on the were one start the search from (before the first Hello works otherwise it will find the next "first" Hello of the paragraph.
    I said sort of because I naively presumed that GREP styles would work like GREPS, dumb hey.
    I was really looking to use these GREPS in GREP styles, well you can't.
    In a GREP style
    (Hello(?!=$)) or any of its variants will apply the style to all occurrences of Hello in the paragraph.
    I can partially circumvent this problem by adding a second GREP STYLE which applies an anti style to all words after the first Hello (?<=Hello).*
    i.e. I have a want my first Hello to be bolded then set the first style for bold and the second to regular.
    This however is not practical if one wants to auto style more than one word in this way in other words to do the same for the first Hi and the first Hello in the paragraph.
    As a regular GREP solution providing that one starts the GREP search before the first occurrence of Hello It will work.
    2 & 4) First and Last Hello in the story
    Again these GREPs don't work using GREP styles, this I think is because GREP paragraph styles only look within the one paragraph at a time they are applied to.  So they can't look at the preceding or following paragraphs to see if they contain Hello or not.
    If I am correct I see no work around to this and am will to pay 10 Pounds, Euros or Dollars to whoever comes up with a non-script fully functional  GREP styles solution for this (I think my money's safe)
    Regarding the regular non styled GREPs they nearly work as stated.
    When (?s)(Hello)(?!.*?\1) is used to find the last occurrence of Hello in the story, if the find tab is used it will firstly find the last Hello of the story then it will go back and find the one before that!! then it will go onto the next story.
    Using the GREP in script works as stated.
    The easiest way of course to find the first and last Hello in a story, document etc. by script would be
    app.findGrepPreferences.findWhat = Hello"
    myFinds = myWhatEver.findGrep();
    First occurrence   myFinds[0], last occurrence   myFinds[-1].
    HOWEVER NOT PARTICULARLY EFFICIENT!
    3) Last occurrence  of Hello in paragraph.
    This one works perfectly both with regular GREPS and GREP styles.
    In summary
    GREP STYLES: only the (Hello)(?!.*?\1) last Hello in the paragraph GREP works.
    GREP FIND TAB: the first Hello in the paragraph GREP finds the first Hello after the cursor, the first in the story works in the limited way as written, last in story has the problem of finding the second last Hello after finding the last Hello, Last in paragraph works flawlessly.
    GREP SCRIPTING: all work without problem except for the first Hello in the story that has the problem of needing to extract the last 5 letters which for my automatic text / GREP changer is a bit of a problem but for general scripting would not be problematic.
    Once again Marc thanks for your input, I doubt there's much if anything  to add on the topic maybe Laurent Tournie from indigrep.com might have some ideas.  I don't know his contact details so if you think it's a good idea please can you send him a tweet / mail.
    Regards
    Trevor

  • Finding the no. of occurence of a particular word in a paragraph.

    Hi
    If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
    for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
    Paragraph: Desperate to avoid another market-crushing defeat, House leaders won key converts Thursday to the $700 billion financial industry bailout on the eve of a make-or-break second vote.President Bush and congressional leaders lobbied furiously for the dozen or so supporters they'd need to reverse Monday's stunning setback and approve a massive rescue plan designed to stave off national economic disaster.
    "A lot of people are watching," Bush pointed out ? as if lawmakers needed reminding ? and he argued from the White House that the measure was the best chance to calm unnerved financial markets and ease a spreading credit crunch. Anything but reassured, investors sent the Dow Jones industrials plunging another 348 points lower.
    ANY IDEA GUYS???

    ping.sumit wrote:
    Hi
    If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
    for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
    ...ping.sumit, you've been a (fairly) active member on these forums for almost a year now. Do you really have no idea how to begin solving this problem?

  • Find exact word in text file tht is present in an excel sheet

    Hi all,
    i want to find words in an text file.
    but the criteria is i want to search words which r already listed in another excel sheet and change the color of these word.
    i used FileInputStream
    and also BufferedInputStream
    cany anyone help me with this

    hi kajbj,
    can u plz tell me how to do in VBA then
    will find out the way to do in java
    Thanx

  • Anyway to highlight a particular word in text?

    I'm trying to implement some necessary features using htmlText (http://livedocs.adobe.com/flex/3/html/help.html?content=textcontrols_04.html). One thing I need to do is highlight a particular word in a sentence. Something along the lines of
    This is a sentence with a <highlight> highlighted </highlight> word.
    None of the tags in the aforementioned list seem to be able to be able to do anything like this. I was hoping for a backgroundColor attribute in the font tag, or something. I've also looked at the CSS capabilities, etc... and simply using setStyle("backgroundColor" ...) wouldn't do any good, as I need to highlight only one word.
    It seems we'll just have to find another way to emphasize the text in question, but before I abandon all hope, am I missing anything?

    I think you already know this, but you can change the color of the text with <font color=""> and/or make it bold with <b>, and I think you can make it italic with <i> or <em>.
    Like I said, I think you already knew that but thought I'd mention it.
    You could use the drawing API to draw a rectangle under the word, but with different fonts and font sizes that would be difficult to get right and consistent.
    If this post answered your question or helped, please mark it as such.

  • Change the background color of a particular word without changing the background color of the rest of the text in a textbox

    Hello,
    I'm designing my own website and want to know how to change the background color of a particular word without changing the background color of the rest of the text in a textbox. If i can't do this, how can I create a Table, similar to Excel with iWeb?
    Thank you very much!
    Roger.

    If i can't do this, how can I create a Table, similar to Excel with iWeb?
    Read this :
         Create and add a TABLE in iWeb »
         More about a TABLE in iWeb »
         Sample 1
         Sample 2

  • Here's how to find the right word in a string

    I needed to find the rightmost word in a string. I didn't find a simple formula in these forums, but I now have one, so I wanted to share it. Hope you find it useful.
    Assuming that the string is in cell A1, the following will return the rightmost word in the string:
    RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1," ","*",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

    I found the problem. Whatever character was being used in the substitution was parsed out by the forum parser. I replaced it with "œ" (option q on my keyboard).
    =RIGHT(A1,LEN(A1)-FIND("œ",SUBSTITUTE(A1," ","œ",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))
    Still needs an error check for a single-word "sentence" and to remove the trailing period but it does seem to work. Pretty slick.
    Message was edited by: Badunit
    I see below that the problem was fixed by the OP.
    Message was edited by: Badunit

  • How to find the exact word in a long text?

    Hi,
    Scenario:
    I have long text containing the system status of the equipment.
    Issue:
    I need to find the exact word from the list of the statuses. I have tried to use the FIND keyword but it does not work for all the cases.
    Example:
              FIND 'REL' IN <status_list> IGNORING CASE.
              if sy-subrc = 0.
              " do something
              endif.
    If the status list contains the word 'RELR', the sy-subrc is set to 0 (which may be because it searches the list based on a pattern) but I want to get the exact match.
    Can anybody suggest me on this.
    Regards
    s@k

    >
    siemens.a.k wrote:
    > Dear Kiran, Vasuki,
    >
    > The data type of status list is char with length 40.
    > The status list:
    >
    > Case 1: list -  REL  MANC NMAT PRC  SETC
    > FIND 'REL ' IN <status_list> IGNORING CASE
    > the sy-subrc is set to 0
    >
    > Case2: list - CRTD MSCP NMAT PRC  RELR SETC
    > FIND 'REL ' IN <status_list> IGNORING CASE
    > the sy-subrc is still set to 0 even though the list does not contain the word 'REL'
    >
    > I have also tried using
    > if <status_list> CS 'REL'
    > and
    > if <status_list> CS 'REL '
    >
    >
    > Please do let me know if I am anyway unclear about issue...:)
    >
    > Regards
    > s@k
    This is becacuse when you check
    > Case2: list - CRTD MSCP NMAT PRC  RELR SETC
    It is having RELR so that is the reason you are getting subrc = 0.
    >Ok try CS it should work perfectly.
    It seems... CS also not the correct answer
    (It will count RELR)  below thread sachin is correct ...Do that way ....
    Regards
    sas
    Regards
    Sas
    Edited by: saslove sap on Jan 25, 2010 6:58 AM

  • Count the ocurrences of a particular word in the log file of content server

    Hi all,
    How can we achieve this.
    Thanks,
    Chely

    ping.sumit wrote:
    Hi
    If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
    for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
    ...ping.sumit, you've been a (fairly) active member on these forums for almost a year now. Do you really have no idea how to begin solving this problem?

Maybe you are looking for

  • LaserJet P3005 Intermitent printing issue

    Hi there, We have a LaserJet P3005  on a local LAN which receives print jobs from Windows XP users/ Word 2003 and also print jobs from SAP. What we have noticed is that from time to time some pages output with a lot of the characters on the page sque

  • How to install Classic on OS 10.3.9

    Hi there. I have an iBook G4 that runs on OS 10.3.9. Last spring it died, I took it to Apple and it came back to me with a new hard drive--so basically it was like a brand new computer. I rarely use the Classic environment and went to use it today an

  • Creating my own transition

    is there a place that will give a tutorial on how to do this? I have a video transition in my video file that I want to use for the menu also... any suggestions?

  • Unity 8 upgrade and delay when accessing voicemail via TUI

    We just recently upgraded our Unity UM 7.x with FO to 8.03. when hitting messages and after entering your password you just get dead air. when going back in and doing it again it works again. this is happening to everyone. i read in the release notes

  • Initial loupe view appears a little soft in LR3

    Windows 7 64bit Ultimate 12 GB ram 30 inch monitor resolution 2560x1600 12000+ images in catalog Standard previews set to 2048 Medium Detail in loupe view seems to be soft.  When I zoom in, the detail is great.  When I zoom back, the detail remains g