Search for a word in a string.

Hello everybody,
Could anybody help me how to search for a word in a string ?
Example: I have a string as below:
String[] weather = {"snow", "rain", "sunny", "temperature", "storm", "freezing"};
And I have a sentence like this:
"Today is a sunny day"
I want to break this sentence to pickup the word "sunny" and search this word in String[] weather to see if they match. How could i do that?
Thank you very much. I really appreciate.
still_learn

1 iterate through the strings in your array.
2. use String.indexOf(...) to test if the query string is present in the string

Similar Messages

  • Tell me Logic for search for duplicate words(or strings) in a large file.

    Search for duplicate words (or strings) in a text file containing one word per line. For each word that occurs more than once in the flat file output should be as follows
    <word> <number of occurrences> <line numbers in the file where the word occurs>
    For example, if the word Hello occurs thrice in a file at lines 100, 178 and 3456 the output should read
    Hello, 3, [100, 178, 3456]

    Incidentally i wrote similar code some days back. You need to do some modifications to get the exact output you want, but i hope it will be of some help.
    One more thing its written using JAVA5
    public class Test
         private static final String COLLECTIONS_TEXT = "C:\\Documents and Settings\\amrainder\\Desktop\\Collections.txt";
         public static void main(String[] args) throws IOException
              findDuplicateWords();
         private static void findDuplicateWords() throws IOException
              Collection<String> words = new LinkedHashSet<String>();
              File file = new File(COLLECTIONS_TEXT);
              StreamTokenizer streamTokenizer = new StreamTokenizer(new FileReader(file));
              int token = streamTokenizer.nextToken();
              while(token != StreamTokenizer.TT_EOF)
                   if(token == StreamTokenizer.TT_WORD)
                        words.add(streamTokenizer.sval);
                   token = streamTokenizer.nextToken();
              System.out.println(words);
    }Cheers,
    Amrainder

  • How to search for a word in a text editor

    Hi,
       I have created a custom container and added some text to it. Is there any method to search for words in this?

    Lilan,
    To search a character field for a particular pattern, use the SEARCH statement as follows:
    SEARCH <c> FOR <str> <options>.
    The statement searches the field <c> for <str> starting at position <n1>. If successful, the return code value of SY-SUBRC is set to 0 and SY-FDPOS is set to the offset of the string in the field <c>. Otherwise, SY-SUBRC is set to 4.
    The search string <str> can have one of the following forms.
    <str>
    Function
    <pattern>
    Searches for <pattern> (any sequence of characters). Trailing blanks are ignored.
    .<pattern>.
    Searches for <pattern>. Trailing blanks are not ignored.
    *<pattern>
    A word ending with <pattern> is sought.
    <pattern>*
    Searches for a word starting with <pattern>.
    Words are separated by blanks, commas, periods, semicolons, colons, question marks, exclamation marks, parentheses, slashes, plus signs, and equal signs.
    <option> in the SEARCH FOR statement can be any of the following:
    ABBREVIATED
    Searches the field <c> for a word containing the string in <str>. The characters can be separated by other characters. The first letter of the word and the string <str> must be the same.
    STARTING AT <n1>
    Searches the field <c> for <str> starting at position <n1>. The result SY-FDPOS refers to the offset relative to <n1> and not to the start of the field.
    ENDING AT <n2>
    Searches the field <c> for <str> up to position <n2>.
    AND MARK
    If the search string is found, all the characters in the search string (and all the characters in between when using ABBREVIATED) are converted to upper case.
    Pls. Mark

  • How to search for upper/lower case using string using JAVA!!!?

    -I am trying to write a program that will examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears.
    -I also have to use a JOptionPane.showMessageDialog() to tell the user how many upper and lower case e's were in the string.
    -This will be repeated until the user types the word "Stop". 
    please help if you can
    what i have so far:
    [code]
    public class Project0 {
    public static void main(String[] args) {
      String[] uppercase = {'E'};
      String[] lowercase = {'e'};
      String isOrIsNot, inputWord;
      while (true) {
       // This line asks the user for input by popping out a single window
       // with text input
       inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
       if ( inputWord.equals("stop") )
        System.exit(0);
       // if the inputWord is contained within uppercase or
       // lowercase return true
       if (wordIsThere(inputWord, lowercase))
        isOrIsNot = "Number of lower case e's: ";
       if (wordIsThere(inputword, uppercase))
         isOrIsNot = "number of upper case e's: ";
       // Output to a JOptionPane window whether the word is on the list or not
       JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");
    } //main
    public static boolean wordIsThere(String findMe, String[] theList) {
      for (int i=0; i<theList.length; ++i) {
       if (findMe.equals(theList[i])) return true;
      return false;
    } // wordIsThere
    } // class Lab4Program1
    [/code]

    So what is your question? Do you get any errors? If so, post them. What doesn't work?
    And crossposted: how to search for upper/lower case using string using JAVA!!!?

  • Search for multiple words in a field?

    is there a way to search for multiple words in a field? for example, if i have a metadata field called NOTES that contains the string "Joe and Bob created this version on Sunday" is there a way to search for "Sunday, Joe, Bob" and have it return the asset?

    Search using the "Matches Word" option instead of "Contains". That will limit your results to only assets that have a field value that includes all three of those terms. If they are not all included in the same field value, it will not return a hit. So if "Sunday" were in Keywords and "Joe" & "Bob" are in Notes, you would not get a hit for that search with "Matches Word".
    "Contains" searches for the contiguous string in any field on the assets.
    Further, if you add your Notes field to the Metadata Group "Asset Filter", it will appear in your advanced search options, asset subscription filters, and search expired responses. Then you can specifically limit the search to that field and choose from "Matches Word', "Contains", and several other search filters. Note that when you use "Matches Word" this way, you need to eliminate spaces from your comma delimited list of words or you will not get the search hits you want.

  • Search for a word in a sentence

    hi,
    Is there a function module which can search for a word in a sentence or string?
    thanks,
    raksha

    If String1 CP 'CNF# ' or String1 CP '# CNF' or String1 CP '*# CNF# *'.
    flag = 'True'.
    endif.
    CP (Contains Pattern):
    The complete string string1 matches the pattern.
    The pattern can contain ordinary characters and wildcards.
    '*' stands for any character string and '+' denotes any character.
    'ABCDE' CP 'CD' is true;
    'ABCDE' CP '*CD' is false;
    'ABCDE' CP '+CD' is true;
    'ABCDE' CP '+CD*' is false;
    'ABCDE' CP 'BD*' is true;
    The character '#' has a special meaning. It serves as an escape symbol and indicates that the very next character should be compared "exactly".

  • How do I search for a word through multiple files in my directories ??

    Hello everyone
    How do I search for a word through multiple files in my directories ??
    I am guessing one tedious way to do it would be to pass all the file names as command line arguments but I"m sure there exist a much easier and faster way to do it.
    Thanks a lot

    You need to pass only the directory name as parameter and then retrieve the files(recursively throug subdirs or not, however you wish) of that directory.
    There were at least 2 threads yesterday on how to retrieve files from directory, and there are many others in the archive so I leave the search part to you ;)
    HTH
    Mike

  • Windows 8.1 PC, using reader, when searching a folder containing approx 100 doc's. If i search for a word, no results are returned. only the doc names can be found but nothing from within the doc. This is a new problem and was not the case before.

    Windows 8.1 PC, using reader, when searching a folder containing approx 100 doc's. If i search for a word, no results are returned. only the doc names can be found but nothing from within the doc.
    This is a new problem and was not the case before.

    Works perfectly fine for me with the latest Reader version (11.0.09).
    You write that it worked "before"; before what?  An update?  Update from what version to what version?

  • How to search for perticular substring in given string.

    Hi, Can any one tell me how to search for perticular substring in given string.
    example:
    I have to search for CA in given Order type it may be CA10 or CA15. Please Do the needful.

    Hi Aniruddha,
    check this...
    Data var string,
    var = 'India'.
    search var for 'Ind'.
    if sy-subrc = 0.    " var having ind
    Message 'Ind found' type 'I'.
    else  .            "var not having ind
    Message 'Ind not Found' type 'I'.
    endif.
    thanx
    bgan.

  • BUG: Searching for the word "united" in Contacts returns far too many results

    To recreate this bug:
    1. I open the Contacts App on my iPhone 5 running iOS 6.0.1.
    2. In the search field within the app, I search for the word "united." (For example, if I am trying to located the address book card for United Airlines).
    3. Instead of showing me just the results of companies/people that have the word "united" in their name or notes field, the app returns almost every single one of my contacts as a search result, EVEN THOUGH THESE PEOPLE DO NOT HAVE THE WORD "UNITED" IN THEIR NAME, DESCRIPTION, OR NOTES FIELD.
    I think this might be happening because I have used the iOS feature of connecting my Contact App with Facebook.  Because of this, many of my contacts have the word "unified contact info" in their description. Although this doesn't entirely explain why searching for the word "united" would show "unified contact info" contacts, the Facebook/Contacts App connection may have something to do with this bug.
    Regardless, if I search for the word "united" on my iPhone, the Contact App still returns almost every single contact as a search result, even though the word "united" cannot be found within those contacts.

    I think it is because the system adds "United States of America" to every address by default.
    You need to search using different parameters, for example, "Airlines".

  • Search for more words one time

    Goodmorning, as long someone could help me with the other issue http://forums.adobe.com/thread/1057325?tstart=0 I have another question for you.
    I need to search for a specific list of words but I want to search only one time... So for example if I'm searching 3 different words HELLO - GOODBYE - CIAO I want that acrobat perform the searches in the same time and let me see how many times the words are repeated.
    I try with the advanced search but I can only search one word at time...  I see there is a command under tools>protection>find and remove text (hope I have translate right from Italian software) to search for different words in the same time but the problem is that it can't report how many times thw words are repeated. As you see I need a mix of the two tools
    Do you have some suggestions?
    Hope to read you soon. Thanks,
    Luca
    PS: I know I can do that with the boolean expression but in this way acrobat doesn't separate the rusults.

    It will work with any of the smart album criteria - file menu ==> new smart album
    The easiest way to see is to take a look at what is available there - and make a smart album or two - if you don't like them just drag them to the iPhoto trash and do another one
    LN

  • Will not search for a word in pdf file. Using Windows 7

    Like most I have used Acrobat reader for viewing PDF files for years.  I recently upgraded to Windows 7 from XP.  I have tried to search a PDF file for a word and it always comes up with none found even though I search for a word that is displayed in the document I'm looking at.  Any advice?
    Regards,
    Dwight

    If the PDF is not a scanned image, can you share it with us: https://forums.adobe.com/thread/1070933

  • Searching for a word or phrase in a file on NSS Pool/Volume

    I have encountered a strange issue in that if I search for a word or phrase in a file at any level of the volume, from the root, down to sub folders, I get different results from 2 or more PC's.
    Workstations are all Win XP SP2, Novell Client 4.91 SP4 for Windows
    Server NW 6.5 SP6 with all post SP's installed.
    I have ran a nss /PoolRebuild=POOLNAME and a NSS /VisibilityRebuild=VOLNAME
    There is only one volume on this pool.
    And I still encounter the same results.
    As one example:
    On my Admin workstation When I search the top level Folder of Closed Client folders for the word chronology, I get 2 files returned named chronfile1 and chonfile2, when I search from any other workstation (I have tried 4 different workstations at this point) at the same folder level, for the same word Chronology, I get multiple files with the Word in the File, but I do not see files chronfile1 or chronfile2. Likewise, the file names returned form the search results on the other workstations, are not returned in the search list ran on the admin (Mine) workstation. And yes, I am logged in as admin on the other workstations when running the search.
    So far, this issue is only appearing on 1 volume.
    Thoughts?

    Originally Posted by ataubman
    If you log in to the second PC as Admin, does the symptom move? IOW does it follow the user or the workstation? If the user you may have some odd file system rights set, although your specific results you report are puzzling.
    I'm assuming you are using the Windows desktop search tool?
    I ran a NSS /PoolRebuild last night which fixed an issue the workstations not being able to see the 2 files in question.
    Previous night I had just performed an NSS /PoolVerify.
    Part of the other anomoly, the other workstations seeing more files than the admin workstation (I feel so Stupid, after 25 years you think I'd be able to spot the obvious) the reason the other workstations were returning files that the Admin workstation was not - Admin workstation doesn't have Word Perfect installed.
    Somebody, give me a Gibbs head slap, now!

  • Firefox randomly does an automatic search for a word I type and redirects to some website. Any ideas why?

    I've been having this problem for awhile now. If I type a word while using firefox (in a form, searching a page for that word/phrase, etc.), Firefox will later (at a seemingly random time) do an automatic search for that word/phrase and redirect me to some site (e.g. if I search a page for 'history', Firefox will at a random time, redirect me to, for example, history.com). I have no idea what might be causing this, and it is really annoying when I'm filling out a form online and Firefox randomly goes to some site, interrupting what I was doing at the time.

    Do you have that problem when running in the Firefox SafeMode? <br />
    [http://support.mozilla.com/en-US/kb/Safe+Mode] <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    If not, see this: <br />
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]

  • Search for "A word or phrase in the file" in .trc files gives no result

    Hi
    When i Search through Explorer using search for "A word or phrase in the file" in .trc files I get no result.
    Probably because these files are of type "Microsoft Network Monitor Document".
    But I can open them using Notepad, so why can't I search for a word in these files?
    I there another way to search?
    Normally I ofcourse use Visual Admin. but there are a lot of trace files so it would be nice to do this kind of search
    br Peter

    Hi Peter,
    This is a known problem, see http://support.microsoft.com/kb/309173
    An alternative is to use other tools which search even faster than the slow MS search does.
    Hope it helps
    Detlev

Maybe you are looking for