Help me about Searching for a Substring within a String

Hello everybody,
I have a problem like this:
Assume i type a sentence from keyboard: "I want to play football"
And computer will look for the word "football" to see if this word is in that sentence.
In this case, computer found it.
That is it ! Could anybody help me about this ?
Thank you very much in advance.
still_learn

Use the String.indexOf() method:
String original = "I want to play football";
int result = original.indexOf("football");
if (result != -1)
System.out.println("computer found it");
If the word "football" is in the original String, the indexOf() method will return the index of the word. If it does not find the word "football", it will return a value of -1. The String API is full of useful methods.
fitz

Similar Messages

  • Searching for a substring within a string

    can someone reccomend a simple way to search for a substring within a string and count the number occurences of that substring.
    The substring and the string will be provided as command line parameters.
    Thanks
    gg

    A simple way would be to use the indexOf methods in String:
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
    Not sure what this has to do with event handling though :-P

  • 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.

  • Looking for a substring within a string (regexp)

    Hi folks,
    I want to select a substring from a string
    string:
    21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY
    or
    21;0000;4145054;4;A;4 goldglamsnu XEOFX,198877,XEOFX YWY,1,YWY
    I'm looking for the substring:
    YWY,1,YWY
    and try this SQL statement
    SQL> select REGEXP_substr('21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY' ,',[^YWY]+[0-9]')
    2 from dual;
    REGEXP_
    ,117107
    I don't know where my mistake is. Can anybody please help me?
    Database Version 11G R2
    Thanks,
    ben
    Edited by: ben512 on May 14, 2013 5:05 PM

    Hi,
    ben512 wrote:
    Hi folks,
    I want to select a substring from a string
    string:
    21;0000;4145054;4;A;4 mit ALU XEOFX,117107,XEOFX YWY,1,YWY
    or
    21;0000;4145054;4;A;4 goldglamsnu XEOFX,198877,XEOFX YWY,1,YWY
    I'm looking for the substring:
    YWY,1,YWYWhy do you want that substring. Do you always want the last 9 characters of the string?
    If you're looking for a substring that starts with 'YWY', and then has any number (including 0) of commas, digits, and additional 'YWY' strings after it, then:
    REGEXP_SUBSTR ( str
               , 'YWY[,[:digit:]]*)
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, maybe 5 or 10 rows), and also post the results you want from that data. Include examples of any special cases you need to handle (e.g., the target pattern is not found at all, or it is found at 2 different places in the string).
    Explain, using specific examples, how you get those results from that data. Say what your business rules are.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • How do I search for a word within a web page

    I would like to be able to do a search for a pecific within the page currenly viewed in the browser. Is there a way to do that in Firefox?

    Hi JossefPerl,
    Searching on a page is actually really easy. You can just hit ''CTRL + F'' to use the search feature. You should take a look at the Knowledge Base article on [[Searching within a page]] for more information.
    Hopefully this helps!

  • Searching for a substring

    after running through the forums i couldn't find anything that related to my question. so here it is.
    to search for a substring, do i have to search for each individual character or is there an easier method...
    for example:
    String john,paul,mark,fabio,greg,park,rego
    if i wanted to find all the strings with "ar" in them, would i have to search for a, and then r and check if the position of r is +1 a??
    or is there an easier way??
    thanks for your help!

    The documentation is your friend.
    http://java.sun.com/j2se/1.4.1/docs/api/index.html
    Look up what the method indexOf(String) of the class java.lang.String does.

  • Help will not search for search term

    CS6, Windows XP. When accessing online help for CS6 applications, InDesign for example, InDesign Help / Help and Tutorials screen comes up. There is a box, Adobe Community Help with space for a search term and magnifying glass icon and the icon of the application for which I want help.  When I type in the search term and click on the magnifying glass or hit Enter,  nothing happens. Help does not search for term in question. What am I missing?

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

  • Search for a song within a playlist in iTunes 11

    I just want to know how do I search for a song within a playlist. I don't want to search the entire music library just one single playlist.

    Got it. I have to deslect the Search Entire Library in the search field

  • Search for a space within a text field

    Hi All
    I am trying to search for a sapce within a text field but sofar not being very successful. I have used:
    FIND search_str
               IN text_str
               MATCH COUNT  lv_mcnt
               MATCH OFFSET lv_moff.
    where search_str = TYPE c VALUE ' '.
    I am looking a way of searching a character within the string using ABAP (like INSTRING in other languages). If you have similiar codes - Could you please post me a copy - Thanks

    HI
    Check this..
    DATA string7(30) TYPE c VALUE 'This is a little sentence.'.
    WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.
    ULINE /1(26).
    SEARCH string7 FOR 'X'.
    WRITE: / 'X', sy-subrc UNDER 'SY-SUBRC',
                   sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR 'itt   '.
    WRITE: / 'itt   ', sy-subrc UNDER 'SY-SUBRC',
                       sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR '.e .'.
    WRITE: / '.e .', sy-subrc UNDER 'SY-SUBRC',
                      sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR '*e'.
    WRITE: / '*e ', sy-subrc UNDER 'SY-SUBRC',
                    sy-fdpos UNDER 'SY-FDPOS'.
    SEARCH string7 FOR 's*'.
    WRITE: / 's* ', sy-subrc UNDER 'SY-SUBRC',
                    sy-fdpos UNDER 'SY-FDPOS'.
    Thanks ,
    Praveen

  • 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 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

  • How can I use SQL to search for a pattern within a field?

    Hello, Frank, Solomon, ect
    I am now faced with this particular scenario, I've got the SQL to search through a field to find text within the field, but I have to know what it is before it can look for it.
    What I have to do is this:
    Search through a field, for a pattern, and I won't know what the data is I am looking for. Can this be done in SQL?
    For instance, Here is my SQL this far, I was helped allot in order to get to this point.
    select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('TABLE1', 'TABLE2')),
           xmltable (str columns result varchar2(10) path '.')
    When you execute the above SQL, you have to pass in a value. What I really need is to alter the above SQL, to make it search for a pattern that exist's within the text of the field itself.
    Like for instance, lets say the pattern I am looking for is this" xx-xxxxx-xxxx" and it's somewhere in a field.
    I need to alter this SQL to take this pattern and search through all the schemas and tables to look for this pattern match.
    Can be done?

    When you use something dynamically within a function or procedure, roles do not apply and privileges must be granted directly.  So, you need to grant select on dba_tab_cols directly.  If you want to do pattern matching then you should use regular expressions.  The following example grants the proper privileges and uses regexp_instr to find all values containing the pattern xxx-xxxx-xxxx, where /S is used for any non-space character.  I limited the tables in order to save time and output for the test, but you can eliminate that where clause.
    SYS@orcl> CREATE USER test IDENTIFIED BY test
      2  /
    User created.
    SYS@orcl> ALTER USER test QUOTA UNLIMITED ON USERS
      2  /
    User altered.
    SYS@orcl> GRANT CREATE SESSION, CREATE TABLE TO test
      2  /
    Grant succeeded.
    SYS@orcl> GRANT SELECT ON dba_tab_cols TO test
      2  /
    Grant succeeded.
    SYS@orcl> CONNECT test/test
    Connected.
    TEST@orcl> SET LINESIZE 90
    TEST@orcl> CREATE TABLE table1
      2    (tab1_col1  VARCHAR2(60))
      3  /
    Table created.
    TEST@orcl> INSERT ALL
      2  INTO table1 (tab1_col1) VALUES ('xxx-xxxx-xxxx')
      3  INTO table1 (tab1_col1) VALUES ('matching abc-defg-hijk data')
      4  INTO table1 (tab1_col1) VALUES ('other data')
      5  SELECT * FROM DUAL
      6  /
    3 rows created.
    TEST@orcl> CREATE TABLE table2
      2    (tab2_col2  VARCHAR2(30))
      3  /
    Table created.
    TEST@orcl> INSERT ALL
      2  INTO table2 (tab2_col2) VALUES ('this BCD-EFGH-IJKL too')
      3  INTO table2 (tab2_col2) VALUES ('something else')
      4  SELECT * FROM DUAL
      5  /
    2 rows created.
    TEST@orcl> VAR search_string VARCHAR2(24)
    TEST@orcl> EXEC :search_string := '\S\S\S-\S\S\S\S-\S\S\S\S'
    PL/SQL procedure successfully completed.
    TEST@orcl> COLUMN "Searchword"     FORMAT A24
    TEST@orcl> COLUMN "Table"     FORMAT A6
    TEST@orcl> COLUMN "Column/Value" FORMAT A50
    TEST@orcl> SELECT DISTINCT SUBSTR (:search_string, 1, 24) "Searchword",
      2               SUBSTR (table_name, 1, 14) "Table",
      3               SUBSTR (t.column_value.getstringval (), 1, 50) "Column/Value"
      4  FROM   dba_tab_cols,
      5          TABLE
      6            (XMLSEQUENCE
      7           (DBMS_XMLGEN.GETXMLTYPE
      8              ( 'SELECT ' || column_name ||
      9               ' FROM ' || table_name ||
    10               ' WHERE REGEXP_INSTR
    11                     (UPPER (' || column_name || '),''' ||
    12                  UPPER (:search_string) || ''') > 0'
    13              ).extract ('ROWSET/ROW/*'))) t
    14  WHERE  table_name IN ('TABLE1', 'TABLE2')
    15  ORDER  BY "Table"
    16  /
    Searchword               Table  Column/Value
    \S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>matching abc-defg-hijk data</TAB1_COL1>
    \S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>xxx-xxxx-xxxx</TAB1_COL1>
    \S\S\S-\S\S\S\S-\S\S\S\S TABLE2 <TAB2_COL2>this BCD-EFGH-IJKL too</TAB2_COL2>
    3 rows selected.

  • How do I search for adjacent words within MS WORD?

    I am new to Mac. I need to search WITHIN MS Word Documents for specific phrases. Example: Jim is a good boy. Spotlight will find all documents containing those 5 words, but not those 5 words together. There has to be a way...
    MacBook   Mac OS X (10.4.8)  

    First, thanks, I did. My naive take is that new plug-ins wouldn't be required.
    Second - I don't know about Google finding every document, but it returns some pretty impressive results, and fast (so long as Google indexes the page in the first place of course). You've never used this feature? I do it all the time when I want to see if there's an internet version of a document I have in my hand.
    Here's a random example the feature in action - I went to boingboing.net and snagged a phrase from the October archives: "You should give props to BabyStyle.com for the blue octopus costume". Here's the link to the October page:
    http://boingboing.net/200610_01archive.html
    and here's the link to the successful Google search:
    http://www.google.com/search?num=50&hl=en&lr=&safe=off&c2coff=1&client=firefox-a &rls=org.mozilla%3Aen-US%3Aofficial&q=%22Youshould+give+props+to+BabyStyle.com+for+the+blue+octopuscostume%22&btnG=Search
    Pretty impressive - the internet is a big place!
    Thirdly, there was a program written for OS 9 called "Gopher" that did just that. It was pretty handy. Come to think of it, it may have been written for System 8! It vanished from publication before there was even a web for it to be distributed on, and when I switched to OS X, it wasn't working well under 9. Of course outside of the personal computing realm, there are well known database programs like Lexis and Nexis that perform exact phrase searches on their databases, which are pretty extensive (at least as large as most document collections on most personal computers, I'd venture). In fact if you've never used those programs they have some pretty powerful functions, like searching for any occurrence of a word within so many words of a second target word.
    I'll give you a couple of examples of where phrase searching might come in handy. Suppose I have a collection of e-mails or correspondence (I guess we all do) and I want to find the one in which I facetiously repeated the punchline to the chicken joke - "to get to the other side". (You have to grant I might have a reason for wanting this particular e-mail, okay?) Of course if I search on "get", "other" and "side" I may wind up with four or five hundred results; those are pretty common words. That doesn't help me much. A phrase search,however, will yield, I dunno, three or four documents. Bingo.
    Or, here. I work in an office creating documents all day long. I've been working in this office, on PCs, for 16 years. That's a lot of documents. I may create three dozen or more on a single subject. The documents are all on the same subject and all pretty much have the same words in them. Maybe I've got a single paragraph printed from one of them and want to find the source document. A simple word search will yield back 80% of the lot. A phrase search typed in from the paragraph is almost certainly unique, however, and will give me my document in a blink.
    (Um, I'd have to move all the documents to a Macintosh to do this, but you get the point I hope.)
    Spotlight says it finds "anything anywhere" on your computer. I would use a feature like this *all the time*. Why shouldn't it be able to do it?

  • Search for certain Characters within set of Characters - in a field

    Hello -
    I know a search can be made within a field for a word, but I am not to sure, or I don't know how to accomplish this...To do a search in a field for certain characters within a larger set of charcters.
    For example: I would search, in the Call Description field, for DXXXX within CA0001DXXXXYYY or search for LXXXX within CA0001LXXXXYYY, the X is numeric characters and the Y's are Alpha characters. Can crystal accomplish this....
    Thanks for your gracious help....
    G.

    Like I said earlier, this code:
    If instr({database_field}, 'DXXXX') > 0 then "String Found" else "Not Found"
    cannot be used in a Record Selection formula.
    The following code can be used in the Record Selection formula:
    Instr({database field}, "string") > 0
    If you wish to search for 'D4444' in the field and return records where a match is found, you would use:
    Instr({database field}, "D4444") > 0
    -Abhilash

  • How can I search for a substring of a email address or a subject

    ... without getting hits on other fields or content.
    Mail 5.0 seems to have removed the ability to restrict your seach to particular fields.  What you get instead is the ability to select 'people' which should be called 'addresses' or 'subjects'.   There seems to be an assumption that the desired end point of a search is a single message.  But I regularly (several times a week) need to search for messages with certain characteristic and then move, copy or delete them. 
    This makes mail completely unusable for me.  Searching has always been a weak point in mail now it is *much* worse.  Any before you ask yes I have submitted feedback to Apple (I have bitched about the searching in every release since OSX released).   What I have suggested is that they have an "enable advanced search" in the preferences > advanced menu.
    I can see where Apple is coming from but turning MacOS into a *purely* comsumer product aimed at the masses is not the way to go.  They don't need to abandon the professional market in order to get the masses.  Those of us who need advanced functionality are perfectly capable of digging into preference to enable it if we are given the ability.
    I wholely support having a simple system that, out of the box, can be operated intuitively by anyone but that is not incompatible with allowing more sophisticated functionality which might confuse less exprienced users from being activated via preferences.
    What I really want is much more complex searching that allow me to find (for example) all emails to a particular domain that mention 'xxxx' in the subject.
    If this trend continues I can see me installing linux on my new MacBook pro for work stuff. 
    Russell, (who has been a Apple fan since well before Mas were invented )

    rful011 wrote:
    What I really want is much more complex searching that allow me to find (for example) all emails to a particular domain that mention 'xxxx' in the subject.
    You can make some relatively advanced searches through Spotlight and in turn, the Mailbox search field in the Mail toolbar.
    Try this for your example, type the following into the search bar in Mail:
    To:domain.com then hit return. This will give you a search token on the To field.
    Type subject:xxxx and hit return, this will give you a search token on the subject field

Maybe you are looking for

  • Report on Sites, Lists and Libraries with Unique Permissions

    I would like to get a report on Sites, Pages, Lists, Libraries, Items and Documents under a Site Collection having Unique Permissions. What is the best way to accomplish that ?

  • Digital Capture direct

    I've been doing some web searching for an answer to this but have yet to discover anything encouraging. So here's my question/problem: I have a nice photo table with a stable crane like rig on the back (Imagine a camera mounted directly overhead look

  • Agent in critical state / Performance critical

    Hi! I have a server that looks like this: What can be wrong? The enviroment is scom 2012 R2. The server has no issues with performance what I can see.

  • Can´t empty my trashcan and my files are not locked

    Can´t empty my trashcan and my files are not locked?

  • WLS JMS bridge not working

    Hi All, I have been looking for a solution for the last two days and this is my third post regarding JMS bridge. I configured ome JMS bridge which initially ,on the monitoring tab, was giving information "Failed to look uo the source adapter" then I