Find first occurence of an integer in a string

Hi all,
I have a number of strings which go something like "MBNA Flow 12a" and I want to separate the integer from the rest of the string so I can parse it, sort the strings into some sort of order according to their integer, and then put it all back together again. The problem I'm having is finding the position of the integer within the string, so that I can take a substring and/or split the string. I've looked it up and I gather that using regex I should be able to find the beginning and end of the integer, using something along the lines of           
Pattern pattern = Pattern.compile("\\d+");
           Matcher matcher = pattern.matcher(temp.getString(1));which I found on another site where someone had the same problem. I've looked at the regex tutorials and according to them this is what I want, but whenever I try it no match is found, and I don't know why. Some sites have claimed that the regular expression has to apply to the entire string, so I would need to also take into account the MBNA Flow etc, something I'm loathe to do as the string is quite unpredictable, but others say that it should work exactly as is.
Any help would be greatly appreciated. :)
Thanks.

silversurfer20 wrote:
Its throwing the exception cause its not finding a match in the string I know there should be a match in. What I'm wondering is why .Call find() before using either group() or start():
import java.util.regex.*;
public class Main {
    public static void main(String[]args) {
        Pattern p = Pattern.compile("\\d+");
        Matcher m = p.matcher("foo 12 bar 34 baz");
        if(m.find()) {
            System.out.println("first number: "+m.group()+", starts at index: "+m.start());
        } else {
            System.out.println("nothing found");
}Output:
first number: 12, starts at index: 4

Similar Messages

  • Finding the position of an integer in a string

    I haven't done much Java programming for the past 3 months, but I'm trying to get back into it now, but I'm having some trouble. I'm trying to break up a string of integers, to store each individual integer in an array.
    So, if I had something like 132412344, a for loop would put them all into separate arrays.
    I know that there is a charAt() function, but is there something like that for integers?

    Do you know whether every single character in the string is an integer?
    If it is, then toCharArray will get you the array. Then you could loop through it to parse each character into an int. You can use Character.digit to do that.
    I doubt that there's any method that automatically splits a string and returns the integers represented by the characters in a string. It seems like too specialized a method. But I could be wrong.

  • Finding multiple occurences of a char in a string

    So I am trying to make a check to see if there is more than one comma in an entry such as the following.
    "Johnson, Mr. Derrik J."
    I figured out that to make sure it has a comma can be...
    if (stringHolder[1].indexOf(",") > 0 == false)
    System.out.println ("");
    System.out.println ("Error G");
    So to make sure there are not more than 1 comma would be? I'm stuck.

    perhaps the simplest way
    if(stringHolder[1].indexOf(",") != stringHolder[1].lastIndexOf(","))

  • [AS CS3] Search first occurence then next search item

    Hi!
    I have a 1000+ page book. I need to change several (2000+) names to character style but only first occurence of that name and then search first occurence of next name. Names are on a text file which i read to AS but if i use
    set myFoundItems to change text
    it searches all occurences of find text and changes to character style.
    What i need is a script that searches first occurence of name "AAA", changes that to character style "Whatever" and then proceeds to search name "BBB" and changes that too. Only first occurences of search.
    It would be wery handy if the second search (BBB) would start right after the "AAA" and not from the beginning of teh story.
    Any ideas?
    Thanks

    On 19/2/08 9:39 PM, "Jukka Lauhalahti" <[email protected]> wrote:<br /><br />> if one could just exit the seach/replace loop after found one item and search<br />> next item in the list from that position would speed the script...<br /><br />It would, but you can't...<br /><br /><br />-- <br />Shane Stanley <[email protected]>

  • First occurence of a value from a  field in the internal table.

    How to select the first occurence of a value from a field in an internal table ?
    I don think , we can use select query .
    Any suggestions?
    provide syntaxs also .

    Hi...
    You have to use this code.
    DATA : Begin of IT_MARA occurs 0,
                 mtart type mara-mtart,
                 matnr type mara-matnr,
                 meins type mara-meins,
              END OF IT_MARA.
    START-of-SELECTION.
      SELECT MTART MATNR MEINS FROM MARA INTO TABLE IT_MARA.
    END-OF-SELECTION.
    LOOP AT  IT_MARA.
    <b>  AT NEW MTART.      "This will trigger for every first/new value of the field
                 <<<<WRITE YOUR CODE here>>
       ENDAT.</b>
    ENDLOOP.
    You can also use.
    LOOP AT  IT_MARA.
    <b> <b>  ON CHANGE OF IT_MARA-TART.   
                 <<<<WRITE YOUR CODE here>>
       ENDON.</b></b>
    ENDLOOP.
    <b>Reward if Helpful.</b>

  • Find first date of open FI periode

    Hi gurus!
    I want to check if the FI period is closed or not. If it is closed I want to find the open period, and then the first date in this period. How would you solve this?
    check if FI period is closed.
    If period is closed.
    - find open period.
    - find first date of open period.
    endif.
    <removed_by_moderator>
    Kind regards,
    Oyvind
    Edited by: Julius Bussche on Oct 27, 2008 12:22 PM

    use fm's FI_PERIOD_DETERMINE and PERIOD_CHECK
    use the result for first date:
    concatenate e_gjahr e_monat '01' into xdate.
    A.

  • Find first line in every column

    Hi All,
    Request:
    I want to find first line in every text frame column.
    Bug:
    If the active document contains single column, two column and multiple column text frames. In that case I am not able to get my result
    Trying script:
    var myDoc = app.activeDocument
    var myTextFrames = myDoc.textFrames.everyItem().getElements()
    for(i=0; i<myTextFrames.length; i++)
          var myTextColumns1 = myTextFrames[i].textColumns[1].lines[0].contents
              alert(myTextColumns1)
    Herewith i attached the error file.
    If active document contains only two column text frame, script run sucessfully.
    If active document contains single column text frame and two column text frame error found as below:
    Could anyone find solution for my request.
    Thanks in advance
    BEGINNER

    Try this,
    var myDoc = app.activeDocument
    var myTextFrames = myDoc.textFrames.everyItem().getElements()
    for(i=0; i<myTextFrames.length; i++)
        for(var j = 0;j<myTextFrames[i].textColumns.length;j++ )
            var myTextColumns1 = myTextFrames[i].textColumns[j].lines[0].contents
            $.writeln(myTextColumns1)

  • Highlight Words - only the first occurence

    Hi,
    I'm using the "Highlight Words" column formating for a report. There, I'm using the item syntax: &P1_RENVOI. Problem is, when the report appear, only the first occurence of the value of item "P1_RENVOI" is in red for every field in that column.
    Is this a normal feature or should all occurences be put in red?
    Thanks in advance.
    ApEx version: 4.2.1.00.08.
    Theme: Business - 3

    Hi,
    I'm using the "Highlight Words" column formating for a report. There, I'm using the item syntax: &P1_RENVOI. Problem is, when the report appear, only the first occurence of the value of item "P1_RENVOI" is in red for every field in that column.
    Is this a normal feature or should all occurences be put in red?
    Thanks in advance.
    ApEx version: 4.2.1.00.08.
    Theme: Business - 3

  • Find first record in a set of record

    I want to find first record in a set of record .What built in function shall i use and which trigger should I use.Please help.

    Hi,
    First_record takes you to the position of that first record, but doesn't gives you the value of the record, you have to get it form the :block_name.item_name
    Jose.

  • Query to find first and last call made by selected number for date range

    Hi,
    query to find first and last call made by selected number for date range
    according to filter:
    mobile_no : 989.....
    call_date_from : 25-april-2013
    call_date_to : 26-april-2013
    Please help

    Hi,
    It sounds like you want a Top-N Query , something like this:
    WITH    got_nums   AS
         SELECT     table_x.*     -- or list columns wanted
         ,     ROW_NUMBER () OVER (ORDER BY  call_date      ) AS a_num
         ,     ROW_NUMBER () OVER (ORDER BY  call_date  DESC) AS d_num
         FROM     table_x
         WHERE     mobile_no     = 989
         AND     call_date     >= DATE '2013-04-25'
         AND     call_date     <  DATE '2013-04-26' + 1
    SELECT  *     -- or list all columns except a_num and d_num
    FROM     got_nums
    WHERE     1     IN (a_num, d_num)
    ;This forum is devoted to the SQL*Plus and iSQL*Plus front ends. This question doesn't have anything to do with any front end, does it? In the future, you'll get better response if you post questions like this in the PL/SQL.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the SQL forum FAQ {message:id=9360002}

  • How to find first non zero value from the numeric value or string?

    Hiii, Every body
              I have one numeric indicator in which some valuse is coming with the decimal value, lets say 0.00013, now i want to find the first non-zero value from this numeric indicator, then what should i do to do so? i have converted it in the string, but i could not find any method to find first non-zero value from that string or either from the numeric indicator????
          Can you please help me, how to do it? i have attached the vi and write all the description inside.
    Thanks in Advance,
    Nisahnt
    Attachments:
    Find first nonzero.vi ‏20 KB

    Just convert it to an exponential string and take the first character .
    Message Edited by altenbach on 05-10-2006 08:00 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FisrstNonzeroChar.png ‏3 KB
    FindFirstNonzeroCharacter.vi ‏20 KB

  • String replace (first occurence)

    Hi:
    I have a input file that contains the following -
    set var=
    set var=%2
    Now, I need to replace the first occurence of set var= with set var=value, so ouptut file should look like
    set var=value
    set var=%2
    Apparently my code seems to change all occurences of set var= inspite of using replaceFirst, can you please point out what I am missing?
    while((varLine = InputFile.readLine()) != null)
                     if(varLine.endsWith("="))
                  new_varLine = varLine.replaceFirst(find_string,replacement_string);
                 OutputFile.write(var_envLine);
                     OutputFile.write("\n");
                }

    uncle_alice wrote:
    Just set a flag when you've done the replacement: boolean didIt = false;Or a sequential program, which can be clearer than adding conditional logic in loops.
    while((varLine = inputFile.readLine()) != null && ! varLine.matches("\\s*set\\s+var\\s*=\\s*"))  {
       outputFile.write(varLine);
       outputFile.write("\n");
    if (varLine == null) return;
    outputFile.write(varLine + replacement_string);
    outputFile.write("\n");
    while((varLine = inputFile.readLine()) != null) {
       outputFile.write(varLine);
       outputFile.write("\n");
    {code}
    IME in debugging more complicated code the less state you have to think about when working out what the computer should be doing at any part of the code, the better. Most flags can be converted to breaks, continues or method calls; finally lets you clean up on early returns.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to use "FIND FIRST OCURRENCE...." with a very long text

    When I store a certain text in variable p_texto  -> FIND FIRST OCURRENCE is ok; sy-subrc = 0.
    When Instead of assigning a text I read a long text from an excel into p_texto variable ->
    FIND FIRST OCURRENCE is not working; sy-subrc = 4.
      DATA: p_texto(5000).
      DATA: posicion TYPE match_result.
      p_texto = 'HI THIS IS THE FIRST LINE#AND THIS ONE THE SECOND LINE'.
      FIND FIRST OCCURRENCE OF '#' IN p_texto RESULTS posicion.
      How could I manage this problem?
      Thank you very much in advance.

    As I told you before, the problem is not the length of the line.
    The problem is that you see in your variable "#", but it is not "#". It could be a carriage return, a tabulator or other character that doesn't know how to display.
    In my opinion you should search for cl_abap_char_utilities=>newline.
    Regards
    Andrea

  • Find first day of any year

    How to find first day of any year using sql? Is there any function for it ?

    Using below SQL you have to just pass the year:
    SQL> select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual;
    Enter value for tyear: 2000
    old   1: select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual
    new   1: select to_char(to_date('0101'||2000, 'ddmmyyyy'), 'Day') from dual
    TO_CHAR(T
    Saturday
    SQL> /
    Enter value for tyear: 2001
    old   1: select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual
    new   1: select to_char(to_date('0101'||2001, 'ddmmyyyy'), 'Day') from dual
    TO_CHAR(T
    Monday
    SQL> /
    Enter value for tyear: 1990
    old   1: select to_char(to_date('0101'||&tyear, 'ddmmyyyy'), 'Day') from dual
    new   1: select to_char(to_date('0101'||1990, 'ddmmyyyy'), 'Day') from dual
    TO_CHAR(T
    MondayRegards

  • 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

Maybe you are looking for

  • PTO Conversion in Time management

    Hi All, I'm trying to convert PTO(Paid Time Off) from Legacy to SAP . My question is that in which infotype I should run the conversion program is that in 2006(Abscence Quotas) or 2013(Quota Correction). Could any body help me on this. Thanks, Raji

  • Motion 5 not allowing me to save custom transitions.  Please help.

    How can I create custom transitions for Final Cut Pro X.  Motion 5 is not allowing me to save custom templates. I have followed the instructions in  Motion 5 user manual...but, it's not working.  Please help.  When I create a category, it reverts to

  • Sub contracting - Subsequent Adjustment

    Hi Experts Sub contracting - Subsequent Adjustment  I have sub contract Whom I sent the material A - 100 Kg to get the Finsished product B - 100 Nos He has delivered the material MIGO done Senario 1 He has utilised the only 95 kg to make 100 nos 2.  

  • Re: javax.servlet does not exists error altough i set all the env. settings

    Include lib and jre/lib path of your java_home in classpath.Putting j2ee jar files in desktop is not a good idea.Desktop executables are sometimes not recognized in classpath.Keep them under a folder in c or d drive.

  • Can You Still Use Plugins in Photoshop 64-Bit?

    What happens to my plug-ins if I install the 64-bit version of Photoshop CS5 or CS4?