Extract x amount of words from a string

hi all just wondered if some can help me with this
String mySting = "This is a test String"
getInput();   // this method returns a string and works
getNoOfWordsInputted(); // returns int of words in the stringthis is where I need the help
I now need to extract getNoOfWords inputted from myString
ie such that if I input "this is " true will be returned
I can implment the following
if (getInput.equals(myString)){
// do Something
}

Still not quite sure what you're after, but if you want to see if the target string starts with a candidate substring, just use the startsWith method.
if (example.startsWith(sub)) ...
or, you can still use the indexOf method, just check for a return value of 0, meaning the index of was at the beginning of the string.
if (example.indexOf(sub) == 0) ...

Similar Messages

  • Extract words from a string

    select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0    Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionI want to extract xyz_xyz,abc_abc words from the string ' select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'') '
    i have tried with this query...
    select regexp_substr('select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'')', 'trunc[^'''']+''') from dual
    can some one help me on this?
    Thanks,
    Mike

    Hi, Mike,
    Mike wrote:
    I apologize for this..
    create table TEMP_TABLE ( col1 varchar2(10),col2 varchar2(10));
    insert into TEMP_TABLE values('   xyz   ','abc      ');
    insert into TEMP_TABLE values('   xyzxyz ','abcabc    ');
    insert into TEMP_TABLE values('   xyz123 ','abc546  ');
    insert into TEMP_TABLE values('xyz','abc');
    commit
    select * from TEMP_TABLE where trim(col1) ='xyz' and trim(col2) ='abc'
    desired output
    col1,col2
    So the correct output is one row, containing these 9 characters
    col1,col2which do not appear in the table. is that right?
    How is that output related to the data that is in the table? Do you want that output to appear if there are any rows where TRIM (col1) = 'xyz' and TRIM (col2) = 'abc' (for example, either of these two rows from you sample data:
    insert into TEMP_TABLE values('   xyz   ','abc      ');
    insert into TEMP_TABLE values('xyz','abc');), and would you want the result set to contain no rows if the table contained no row like that?
    If so,
    SELECT DISTINCT
         'col1,col2'     AS desired_output
    FROM     temp_table
    WHERE     TRIM (col1)     = 'xyz'
    AND     TRIM (col2)     = 'abc'
    ;I hope this answers your question.
    I have a feeling that it doesn't, or perhaps you have more than one question, since this your earlier messages seemed to have something to do with locating text that was surrounded by single-quotes, and the sample data you posted doesn't contain any single-quotes.

  • Extracting various bits of information from a string

    Hi,
    I am interested in extracting various pieces of information from strings (which were originally email bodies). For example email addresses (that are in the body of the email not the "from" field), phone numbers (which could have spaces between, international formats/conventions, ie not all numbers), profession (to match against a list I have), etc etc.
    I am expecting that I would need to use Regex to find emails and phone numbers, and maybe tokenizing the string to match against my list of professions.
    So I am more interested in some high level suggestions of how I should go about this.
    In most cases, the source of the emails will be from 3 known sources. So in these case I will have a pretty good idea of the format/template that the response's will follow ( ie ".... name is XXXX XXXX ....." ) . This would then make extracting the useful information much easier. However, I need to allow for emails from unknown sources where nothing would be known about the format of the email.
    Any help/suggestions/info would be appreciated.
    The Whale

    Thanks.
    Re: function object; You tip about the function object sounds like a very good idea. I have been thinking about the best way to do this and this sounds like a good way to do it.
    Re: Regex - I have not used Regex much but I am assuming it wont be hard to find or create Regex expressions to find phone numbers and email addresses. Although as you say, names could be hard. Although in this case I will just have to rely on locations in known templates.
    Thanks again,
    :)

  • How to read each and every word from a string.

    Hi all,
       I have a string which is having many label numbers. if the string is lv_str, its value is like, 11111111111111##22222222222222##3333333333333.
    I need to move the values alone into internal table. each value should be updated as a single row into one internal table. How to read each and every word of the string and move to an internal table.
    the internal table should be like this.
    11111111111111
    22222222222222
    3333333333333
    Can any one give me a suggestion in this regard.
    POINTS PROMISED.
    Regards,
    Buvana

    Hi,
    If you know the format and length of the data
    Use split at '#' so that you will get the individual values.
    Thean append it to internal table.
    Reward iof helpful.

  • Extract either string1 or string2 from another string

    I have a string of data named "dump" with 500 or more bytes of data that will contain within it either (along with other data)  the word "circle" or  the word "square". (but not both)
    I need to pull which ever one of these two words that is in the string "dump" and to create a string called "type" that contains only  that word.
    Is there an easy way to do this with a line of code or two?
    thanks

    if (FindPattern (dump, 0, -1, "circle", 0, 0) >= 0)
       strcpy (typem "circle");
    else if (FindPattern (dump, 0, -1, "square", 0, 0) >= 0)
       strcpy (type, "square");
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How can i extract using while the time from the string ?

    First time how can i extract the time as string ?
    And second how can i extract the time as DateTime.Now ?
    public static void ExtractDateTime()
    htmltoextract = new Uri("http://test.com");
    client = new WebClient();
    f = client.DownloadString(htmltoextract);
    client.Dispose();
    int index = 0;
    while (index != -1)
    int t = f.IndexOf(firstTag);
    int g = f.IndexOf(lastTag);
    a = f.Substring(t + firstTag.Length, g - t - 8);
    The string look like this: thisisateststring201309202145andthenextimeinthestringis201309202130andthelastofthisexampletimeinthisstringis201309202115
    What i need to do is first time to extract the time as string to a List<string> like this:
    index 0 201309202145
    index 1 201309202130
    index 2 201309202115
    The second time to extract the times as this time format: YYYYMMDDhhmm and also to add the times to a List.
    First time and second time i mean first example and second example. To use my code but first time to extract it as strings second example as the format of YYYYMMDDhhmm
    And i need to use the while and indexof and substring in this cases.

    Is the region always going to be "eu" or are you going to have more than one region.  Since you are reading a string DateTime from different timezone than the computer you are reading the data you have to convert to a different timezone. 
    It looks like you have at least 'is' and 'eu' for regions.  I don't know what offsets you need so try something like this.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Globalization;
    using System.IO;
    namespace ConsoleApplication1
    class Program
    static void Main(string[] args)
    string input = File.ReadAllText(@"c:\temp\test.txt");
    string pattern1 = @"imageUrls = \[[^\]]*\]";
    Regex ex1 = new Regex(pattern1, RegexOptions.Singleline);
    string pattern2 = @"region=(?'region'[^&]*)&time=(?'time'\d{12})";
    Match match1 = ex1.Match(input);
    Regex ex2 = new Regex(pattern2, RegexOptions.Singleline);
    MatchCollection matches2 = ex2.Matches(match1.Value);
    IFormatProvider provider = CultureInfo.InvariantCulture;
    List<DateTime> dateTime = new List<DateTime>();
    foreach (Match match2 in matches2)
    string region = match2.Groups["region"].Value;
    DateTime dt = DateTime.ParseExact(match2.Groups["time"].Value, "yyyyMMddHHmm", provider);
    switch (region)
    case "eu" :
    dt.AddHours(1);
    break;
    case "is":
    dt.AddHours(-1);
    break;
    dateTime.Add(dt);

  • I am reading from an instrument a 1D string array of numbers in ascii. I want to be extract the actual data values from the string. How do I do that?

    labview 6i. Using sr785 instrument.

    Two ways. Use Fract/Exp to Number function on the Strin>Strin Number Conversion palette. It accepts both individual or strin array inputs. Wire your string array in an get an array of doubles out. You can also use Scan From String on the String palette inside of a for loop. The for loop will autoindex the string array in and autoindex an array of doubles out.
    Attachments:
    string_to_double.jpg ‏10 KB

  • How to extract from a string ?

    Hello , I have this string and I need to extract 4 parts (in bold) from the string , my string is :
    '(invoice) dear client : tom cruise you Buy *408* from MENA.CA @ *6.93* 01/10/09 watheeqa'
    What is the best technique to do that?
    Thanks

    Hi,
    oais wrote:
    Hello , I have this string and I need to extract 4 parts (in bold) from the string , my string is :
    '(invoice) dear client : tom cruise you Buy *408* from MENA.CA @ *6.93* 01/10/09 watheeqa'
    What is the best technique to do that?
    ThanksThat depends on how you know the 4 parts are what you showed, and not
    '<b>(invoice) dear client: tom</b> cruise you Buy 408 from MENA.CA @ 6.93 01/10/09 watheeqa'
    or
    '<b>(invoice)</b> dear client: <b>tom cruise</b> you Buy 408 from MENA.CA <b>@</b> 6.93 01/10/09 <b>watheeqa</b>?'
    or
    '(invoice) dear client: <b>tom cruise</b> you Buy 408 from MENA.CA @ 6.93 <b>01/10/09 watheeqa</b>'
    Will there always be exactly four parts you need to pick?

  • Delete the first word in a string?

    Hi, i have a code in which i can extract the first three words in a string. after it's found the three first words, i would like it to remove the first one, what could i add?
    this is what the code looks like:
    import java.util.regex.*;
    class Test187D {
         public static void main(String[] args) {
              String word1;
              String word2;
              String word3;
              String partDesc = "Hi my name is SandraPandra";
              Pattern pattern = Pattern.compile("^(\\w+)\\s+(\\w+)\\s+(\\w+)");
              Matcher matcher = pattern.matcher(partDesc);
              //Find the first word of the part desc
              if (matcher.find()) {
                   word1 = matcher.group(1);
                   word2 = matcher.group(2);
                   word3 = matcher.group(3);
                   System.out.println (word1 + " " + word2 + " " + word3);
    } Thank you in advance

    Take the length of the first word, plus one for the length of the space, that's how many characters to remove. Take the substring of the original string from the end of the removed part to the end of the whole string. Look up the String methods length(), and substring().

  • Extract words from JSP into text file

    Hi,
    I have a big problem:
    I want to extract selected words from a jsp file.
    Following are found in one of my jsp file:
    E.g.
    1) <td width="217"><font face="verdana,arial" size=2>ORGANISATION UNIT NAME<font color="#FF0000"> <font
    id="fontMandatory">*</font></font>
    I want to retrieve "ORGANISATION UNIT NAME"
    2)errPrompt(frm.txtDesc, "Maximum length is just 100 character only");
    I want to retrieve "Maximum length is just 100 character only"
    I try String tokenising, then check that is the token ends with ">", then the next token is the one
    I want, then loop until "<" is found. BUT this would not work as there is no spacing between some of
    the tags and the words.(e.g. <p>abc)--> This cauese the whole token to be <p>abc, so the "abc" will
    not be extracted as it does not have a "ends with >" in front of it.
    Even with using ">" as a checking does not work for pop up messages, as it does not have tags(refer
    to e.g 2).
    Please reply a.s.a.p...
    Really urgent!!
    Thank You
    Michelle

    for extracting the HTML tags, u can use DOM/DHTML
    I dont remember the syntxes, how to use, but i know that it is possible, just go thru' the DOM/DHTML
    Regards,
    Ritesh

  • How to extract an integer or a float value from a String of characters

    Hi i have a problem getting to a float value within a string of characters..
    for instance the string is
    "numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
    how do i store 700.0 in a float variable
    remember the string is obtained from an inputfile
    so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above String
    This is all i have so far:
    String c;
    String Array[] =new String[g]; (i used a while loop to obtain g(the nubmer of lines in the file))
    while((c=(cr.readLine()))!=null)
    Array[coun]=c;
    it would be reallllllllllllllllllllllllllllllllllllllly easy if there was a predefined method to extract numeric values from a string in java..
    Edited by: badmash on Feb 18, 2009 5:50 PM
    Edited by: badmash on Feb 18, 2009 5:50 PM
    Edited by: badmash on Feb 18, 2009 5:55 PM

    badmash wrote:
    Hi i have a problem getting to a float value within a string of characters..
    for instance the string is
    "numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
    with the space included
    how do i store 700.0 in a float variable
    remember the string is obtained from an inputfile
    so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above StringHuh?
    Not true.
    Anyway why not use string split, split on spaces and grab the last element (which by the format you posted would be your 700.0)
    Then there is the Float.parseFloat method.
    It is easy.
    And another thing why not use a List of Strings if you want to store each line? (And why did you post that code which doesn't really have anything to do with your problem?) Also in future please use the code formatting tags when posting code. Select the code you are posting in the message box and click the CODE button.

  • How to Extract particular field from a string ( Mapping)

    how to exteract the particular field from the given string:
    ProcessEmp this element has a below string subfields.
    <ProcessEmp>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
    &lt;Employee PersonnelNumber="11111" FirstName="String" MiddleName="String" LastName="String" Department="String" Group="" SapUserID="10flname" EmailAddress="[email protected]" DefaultPassword="*" Status="Success" /&gt;</ProcessEmp>
    how to extract only PersonalNumber, department, EmailAddress from above ProcessEmp into 3 diff fields.
    Thanks
    dhanush.

    Hi,
    You are receiving XML message within a field. To access a particular field from that XML message, you could create a User Defined Function, as suggested by many already.
    You could write UDF using some of the String operation functions. This could include following:
    1. If you need to access field Employee PersonnelNumber, you could get last index of that within string using function lastIndexOf(String str). Pass string "Employee PersonnelNumber="" for this function.
    2. This function would return an index of rightmost occurance of this string.
    3. after this you could get the index of next occurance of ", as the value of field is within quotes. You could use function indexOf(int ch, int fromIndex) for getting the same. You would pass Character as " and index as the one received by previous function.
    4. Now you have index for starting and ending point of value string for desired field.
    5. After this you could use substring(int beginIndex, int endIndex) function by passing first and second index values to retrieve the needed string, which contains value of field.
    Hope this would be helful.
    Thanks,
    Bhavish
    Reward points if comments found helpful:-)

  • Extract int from a string

    Hi,
    I am curious if there is an easy way to extract an int value from a String.
    For example, "Rb23" to get 23. The length of the part in front of the integer is variable.
    Thanks

    this seems to work:
    public int extract(String s) {
         String result = "";
         char c[] = s.toCharArray();
         int j = c.length-1;
         if (!Character.isDigit(c[j])) {
              return 0;
         do {
              result+=c[j--];
         } while (j > 0 && Character.isDigit(c[j]));
         return Integer.parseInt(new StringBuffer(result).reverse().toString());
    }it will return 0 if no numbers are found at the end of the string

  • Invoking methods extracted from a string?!?

    Hi everybody. I hope the subject is not confusing. What I'm really looking for is some Perl-like behaviour in Java. In Perl its possible to execute subroutines (basicly methods) extracted from a string ("&sub()"). Is there anything similar in Java?
    What I would like to do is to process a string and if it has a method (object.getTime()), the method will be called and the return value stored in its place.
    Please let me know if more explanation is needed.
    Thanks in advance for all the help!
    Leo.

    I use a language called MUMPS where you can do that as well - execute strings as commands etc. I don't know much about Reflection but it looks like you can get method (Objects) from strings and execute them as well ...

  • How to return a word from an input string in random

    iam trying to return a single word from an input string.the word has to be selected in random.can u help?
    this is wat i tried so far
    private String findKeyWord(String remark)
    String[] input= stringobj.trim().toLowerCase().split(" "); // am splitting the string here and it gets stored in string array//
    return ????? //i should return any one word in the string in random//
    }

    array[random.nextInt(array.length)]

Maybe you are looking for

  • Distortion on real instruments

    I just downloaded iLife 05 and ever since I have done that I am experiencing unwanted distortion when I attempt to record my guitar. At first I thought the problem may be that my input jacks into my m-audio may be going out because that is the sound

  • Internet radio no longer connects

    I have 1.67 GHz Power PC G4 Laptop running OS 10.5.8. (Yeah it's old). The latest iTunes version it can run is 10.6.3. I have been using the internet radio for as many years as I've had this laptop. Three days ago, when I clicked on any of the radio

  • Error When connecting proxy

    Hi, When I try to connect proxy in application, it is not connecting instead when I check whether it is going through proxy or not it is telling that it is establishing direct connection only. Here I have posted part of the coding. Please If any erro

  • ESS Team Calendar

    Hi In the ESS Leave Request Application , when user  views  the Team Calendar , he cannot see the Employee Name if it is maintained in Korean Language in BackEnd, ( Infotype PA0001-ename) but if the Name is Maintained in English Language , it is appe

  • XI Proxy Problems

    Hi all, I got a strange prob with XI 3.0 and the new SAP ERP. Well what I did is a little configuration in the XI and generated a proxy in the SAP ERP to call it. But when I call it I get this message in the error part in sxmb_moni in the ERP: - <SAP