Find last word in String

I know a way to do this but it is very unsemantic I would think. Is there some sort of method?

DrClap wrote:
prometheuzz wrote:
Of course, one's opinion of what a "word" is might vary...That's right. Apparently the rules for word division in Thai are quite complex.It need not be that exotic. The word "caf" wouldn't even be matched by my approach. It was more meant to let the OP think about his problem (and his description of it).
@Ryan: consider the following four sentences:
And then there was silence...
This thread is Ryan's.
What is e-mail?
I hate that flower called forget-me-not!What would be the last words from them?

Similar Messages

  • Last word of string!

    Hi, My problem is I want to return the last word of a string.......
    I have tried these 2 methods but it didn't worked can anypne help?
    public class news {
              //construct String
    private String str;          
    public static String lastWord(String str) {
         StringTokenizer st = new StringTokenizer(str);
         int tokenCount = st.countTokens();
    // the tokenCount gives you the number
    // of white space separated Strings
    // in the original String
         int count = 0;
         String lastWord = "";
              while (st.hasMoreElements()) {
              count++;
                   if (count != tokenCount) {
                        st.nextToken();
                   else {
                        lastWord = st.nextToken();
              } return lastWord;
    /*public String lastWord(String str) {
         for (int i=0; i<str.length(); i++){
         //str = new StringBuffer(str).charAt(str.length()-1);
         char c =str.charAt(str.length()-1);     
    return (c);
    public static void main (String [] args)     {
              news str = new news ();
              System.out.println("Last word of string is"+str.lastWord("Java technology"));
    }

    It is looking correct code, but my problem that it doesn't complie & give me this error, as I'm new I don't know what this error suppose to mean and why doesn't it compile? :(
    --------------------ERRORS-----------------------
    C:\javahw>javac news.java
    news.java:8: cannot resolve symbol
    symbol : class StringTokenizer
    location: class news
    StringTokenizer st = new StringTokenizer(str);
    ^
    news.java:8: cannot resolve symbol
    symbol : class StringTokenizer
    location: class news
    StringTokenizer st = new StringTokenizer(str);
    ^
    2 errors

  • Find a word in string.

    Hi,
    Say I have the following:
    String sentence = "12345 good morning!";
    How do I get the first word in the above sentence ? Note that the content in the sentence can vary, but I need to get the first word. The length of the first word can vary.
    Any idea how ?
    Best Regards,
    yckok.

    import java.util.regex.*;
    public class GetWord
         public static void main(String[] args)
              String msg = "12345 good morning";
              Pattern p = Pattern.compile("[\\s]+");
              String[] result = p.split(msg);
              System.out.println(result[0]);
    }

  • Finding a word within a string

    Hey everyone,
    Just having a little trouble with something.
    I'm trying to find a word -- that is, not a substring, an actual word as defined by the english language -- within a string.
    For example I don't want "hell" to be found in "hello".. only "hello" to be found.
    Currently i've got two strings, one is the sentance (String input), and one is the word to be found in the sentance (String word). I need the program to find the WORD, and then go back and search for the word again and again and again until it reaches the end of the string.
    This is what I've got thus far:
              for(i = 0; i < input.length(); i++)
                   // This statement checks the string "input" for the string "word" starting at offset 0 (as this is what the variable was first defined as)
                   if(input.indexOf(word, offset) >= 0)
                        // If it finds the word at all, this line increases the offset ahead of this word so it doesn't simply find the same word again
                        offset = offset + (input.indexOf(word)) + (word.length());
                        times++;
              }At the moment this searches for the sub-string, not the WORD which is what I would like it to do.
    What's the easiest way of going about this? I've been fiddling around trying to add extra sections to the if statement, for example
    if((input.indexOf(word, offset) >= 0) && (input.charAt(offset +1) == 32))(32 as in the ASCII character for a space, which would do what I wanted it to do)
    But I eventually get errors because at some stage or another the charAt is going to be higher than the actual length of the String. Plus, this only looks if there's a space next to the word - a word can be valid if it has a ! next to it for example, or a comma...
    Thanks for any help :)
    viddy

    I think there's a word boundary marker in regex. So it'd be "\\w+hello\\w+" or whatever the marker is, to be used with a Pattern instance.

  • To extract the last word in a string

    Hi
    I am using BODS 14.1.1.210 
    I would like to extract the last word in a string in BODS query. How can I achieve this when  I don't know how many words are present in a space delimited string.
    Example
    Input                                              Output    
    My name is Tim                              Tim
    Complicated                                    Complicated
    there is a bird in the nest                 nest
    Please let me know if there is a query function for this one.
    Cheers!

    Hi,
    try this-
    word_ext(fieldname,-1,' ')
    Atun

  • To find a word in a string.

    Please, is there a way to find a word in a string?
    For exemple:
    The string contains... "Hello World Java Sun"
    I need to find the word "Java", and I'd like to do not compair char by char... I'd like to do it faster than one by one...
    Is there a way? How should I do? I was thinking to use something like substring... but even it... I need to compair char by char... (or I didn't?)
    Thanks a lot

    go to search engine and learn the String class it will help u in the future.
         indexOf
    public int indexOf(String str)
        Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that:
             this.startsWith(str, k)
        is true.
        Parameters:
            str - any string.
        Returns:
            if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned

  • Replace last occurrence of a word in string

    Hi,
    I need to replace a last occurrence of a word in string. Form example:
    'I like fruits and also like vegetables'  need to replace last occurrence of "like" which is just before vegetables and not the "like" before the fruits.

    One of the solution to use the last occurrence dynamically
    applicable to prior version of 11g
    SELECT REGEXP_REPLACE (str, 'like', 'hate', INSTR (str, 'like', -1))
      FROM (SELECT 'I like fruits and also like vegetables also like mango' str FROM DUAL)
    applicable to 11g
    SELECT REGEXP_REPLACE (str, 'like', 'hate', 1, REGEXP_COUNT (str, 'like'), 'i') data_col
      FROM (SELECT 'I like fruits and also like vegetables also like mango' str FROM DUAL)

  • Sql query to find the last word in a sentence (column)

    Hi,
    I have to retrieve the last word in a column containing varchar2(text) values.
    If anyone knows the query for this kindly share with me.

    There's also the option of regular expressions in 10g onwards...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'oracle forums is the best resource for oracle intelligence' as l from dual)
      2  select regexp_replace(l, '[[:print:]]* ([^ ]*)$','\1') as l
      3* from t
    SQL> /
    L
    intelligence
    SQL>

  • How to find a specific text(string) in a list (100) programs

    Dear All,
    Wish tou a very happy new year 2009!!!
    please let me know how we can find a specific word(eg: "barrel") in a list of programs/reports/bdc/user exits/field exits/function modules.
    Thanks in advance.
    Kumar.

    hi kumar,
    open EWK1 transaction and search for the word or string according to your requirement.
    Cheers
    Gautham

  • The Firefox find function seems to have become CAPS or non-caps specific, so that typing a word in non-caps will not find matching words with one or more capital letter.

    The find function seems to have changed in Firefox. Before, when doing a (CTRL + F) find, the search was not CAPS-specific or non-caps-specific. In other words, if I typed in "firefox" (no caps), it would find the words "firefox", Firefox", or "FIREFOX", regardless of capitalization. Now, however, the find function will only match the exact same capitalization. This totally undermines the usefulness of the function, and is a major hassle. Please fix it.
    == This happened ==
    A few times a week
    == I noticed in in the last two or so weeks.

    I am having a similar problem. The following page has the word Dangerfield in several times. My browser will get to Dang and turns pink
    http://www.genuki.org.uk/big/eng/HEF/ProbateRecords/WillsD.html
    Is it my Browser or is there a problem with Mozilla?
    I have also noted on other Google searches the same problem. Te term is listed in the page but Ctl F will not find the term

  • How to find last DML operation in oracle ADF

    how to find last DML operation in oracle ADF
    Please help me
    Thanks
    Damby

    In the base EntityIml class, just override doDML() method as I said.
    (see http://docs.oracle.com/cd/E16162_01/web.1112/e16182/appendix_mostcommon.htm
    "Methods for Creating Your Own Layer of Framework Base Classes")
    So, put a some flag in the session.
    You should not call doDML() method in backing bean, it will be called by framework.
    In the backing bean, you only have to get that information from the session, as follows:
    String last_dml_op = (String)ADFContext.getCurrent().getSessionScope().get("last_dml_op");And voila...

  • How to finds specific words in each sentence?

    import java.io.*;
    import java.text.*;
    import java.util.*;
    public class FindingWordsSpecific {
         static String[] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "every Tuesday"};
      public static void main( String args[] ) throws IOException {
               // the file must be called 'myfile.txt'
               String s = "myfile.txt";
               File f = new File(s);
               if (!f.exists())
                    System.out.println("\'" + s + "\' does not exit. Bye!");
                    return;
               BufferedReader inputFile = new BufferedReader(new FileReader(s));
               String line;
               int nLines = 0;
               while ((line = inputFile.readLine()) != null)
                    nLines++;
                   System.out.println(findTheIndex(line));     
               inputFile.close();
           public static String findTheIndex(String sentence){
                String result = "";
                String[] s = sentence.split("\\s");
              for (String s1: s){
                   for (String s2: days){
                        if (s1.equalsIgnoreCase(s2)) {
                             if(s2.matches("every Tuesday")){
                                             }else if (s2.matches("every Wednesday")){
                                              }What is wrong with it because I tried to find "every Tuesday" in
    myfile.txt: "Go fishing every Tuesday and every Wednesday"
    There is big problem with split statement because it takes each word not more than a word.
    I need to have "every Tuesday" not "Tuesday". How to make it correct codes?

    I am going to give you a picture of how the output will look.
    Here are two sentences from myfile.txt:
    Go fishing every Tuesday and every Wednesday
    Meet with research students on Thursday
    I need to read from myfile.txt and to find specific words in each sentences like this output:
    Every Tuesday : Go fishing
    Every Wednesday : Go fishing
    Thursday : Meet with research students
    Ok. make sense? Now I am trying to figure out how to find specific words in each sentence from myfile.txt.
    That is why I have difficult with the splits statement and loops. Like this:
           public static String findTheIndex(String sentence){
                String result = "";
                String[] s = sentence.split("\\s");
              for (String s1: s){
                   for (String s2: days){
                        if (s1.equalsIgnoreCase(s2)) {
                             if(s2.matches("every Tuesday")){
                             }else if(s2.matches("every Wednesday")){
                             }else if(s2.matches("Thursday")){
                             }else{
                                  System.out.println("That sentence is not working");
                return result;
      }So look at the "Thursday" it is working the output because I have split statement to give me only one word not more than
    a word in sentence. So there is big problem with more than a word in sentence like this "every Tuesday" and it won't work at all because of split. Could you please help me how to do that? I appreciated for that help. Thanks.

  • Grep to find any word NOT in quotes

    Hi
    Can someone help me with this grep
    I need to find all words that are NOT in quotation makrs
    For example:
    Hello and "Good Morning"
    I would want to find the words:
         Hello
         and
    but not the words:
         Good
         Morning
    I tried with lookahead and lookbehind like this:
    (?!=")\w+(?!")
    but it just selects one character less
    If anyone can help I'd really appreciate it
    Thanks in advance
    Davey

    Hey guys!
    Thanks a lot for your help!
    @Beginner_X
         Your first grep was almost perfect, however, it didnt find the first word of a story (since it didnt follow a space or a return)
         Your second post worked perfectly!! - Thanks a lot
    @csm_phil
         I was looking to select each word separately, not consecutive words - although this will also come in handy
         Your grep worked, however I had to add the question mark to make it ungreedy
         because if the sentence had 2 quoted words, it would select from the beginning of the line till the last quote
    @Laubender
         For some reason your grep is functioning just like mine - it finds the word Good and Morning
    Thanks again
    Davey

  • How find a word in txt from Java??

    Hi everybody...somebody knows how to find an especific word that is located in file txt from java somebody has the code???
    Thanks in advance

    Here is the code for finding a word in txt file from Java.
    import java.io.*;
    public class FindTextFromFile
        public static String getString(String fileName)
            StringBuffer fileContent = new StringBuffer(); //appending long String objects repeatedly is very costly
            try
                BufferedReader fileReader = new BufferedReader(new FileReader(fileName));
                String line = "";
                while((line = fileReader.readLine())!=null)
                    fileContent.append(line);
                    fileContent.append(System.getProperty("line.separator")); //size of line.separator=2
            catch (IOException e)
                e.printStackTrace();
            return fileContent.toString();
        public static int[] getIndicesOf(String fileName, String findWord)
            String fileContent = getString(fileName);
            int[] indices = new int[(int)(fileName.length()/findWord.length())]; //max possible occurances
            int index=0, from=0, incr=0;
            while ((index=fileContent.indexOf(findWord, from))!=-1)
                indices[incr++]=index;
                from=index+findWord.length();
            indices[incr]=-1; //marking the end of search result storing
            return indices;
        public static void main(String[] args)
            String fileName = "rawTextFile.txt";
            String findWord = "is";
            System.out.println(getString(fileName));
            System.out.println();
            System.out.print("Occurences of '"+findWord+"' found: ");
            int[] indices = getIndicesOf(fileName, findWord);
            for (int i=0; indices!=-1 && i<indices.length; i++)
    System.out.print(indices[i]+" ");

  • First and Last Word on Page

    Hi,
    I am trying to create a document that is similar to a dictionary or an index of information.
    I want the first and last word on each page to be displayed automatically at the top corner and bottom corner of each page, to make navigation in the document easier.
    Is there a way to do this in InDesign?
    (If it is not done automatically, then if there is any shift in the lines, everything will be off, so i would Iike to find a way to do this.)
    Thanks

    That can be done with text variables (only in CS3 and later, though).
    Read http://help.adobe.com/en_US/InDesign/6.0/WS6A9BE096-77B2-4721-9736-797C4912B6C9a.html, the section called "Create variables for running headers and footers".

Maybe you are looking for

  • Relatório de Análise de Vendas

    Problema:  Gerei um a determinada fatura (NFs) com e utilizei um código de imposto com a combinação (ICMS=17%+IPI=15%). O valor total desta nota R$ 115,00 só que quanto puxo o relatório de análise de vendas  o valor que é exibido no campo Total de No

  • How to set up time capsule with ethernet?

    How do I set up a Time Capsule using just ethernet? I have to do a complete backup (1 TB) (AGAIN!) and it will take forever using WIFI. And the instruction manual even says that the first complete backup should be done using just ethernet, --but you

  • How to design Customized ALV report like normal report !

    Hello Friends,               I like to design a ALV report, with sub headers, sub totals, summary total and other summary details like percentage sale, which is not relavent to the fields displayed in the ALV. I know it is possible to get total of th

  • Can't copy and paste files using RDP session in server 2012

    I'm running windows 8, but I have also verified on a windows 7 machine as well. We have server 2012 installed on a machine I use remote desktop to get into. I cannot copy files from my local pc and use paste to get them to the server. I could do this

  • Invisible text?

    I've just installed Pages '08 (v3.0.3) on a MacBook running OSX (v10.6.3). The install seemed to go ok, but I am unable to see anything I type! The text remain frustratingly invisible, no matter what I do to change the font color. I can highlight the