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.

Similar Messages

  • Need help in finding the position of a SubString in a String

    Hi All,
    I have a VARCHAR2 column in my table which has data similar to '152-425-3265-8-5623-45'.
    I want to find the position of the numbers in the column.
    For example:
    If i give 8 - query should return me 4.
    If i give 425 - query should return me 2.
    The numbers are delimited with '-' value.
    Please help.
    Thanks in advance.
    Edited by: 868171 on Jun 24, 2011 4:33 AM
    Edited by: 868171 on Jun 24, 2011 4:34 AM

    do you know the max number of dashes?
    if so
    with t as (select  '152-425-3265-8-5623-45' code, '425' num from dual union
                   select  '152-425-3265-8-5623-45' code, '8' num from dual)
    select code, num, case num when  regexp_substr( code,'[^\-]+',1,1) then '1'
                   when  regexp_substr( code,'[^\-]+',1,2)  then '2'
                   when  regexp_substr( code,'[^\-]+',1,3) then '3'
                   when  regexp_substr( code,'[^\-]+',1,4)  then '4'
                   when  regexp_substr( code,'[^\-]+',1,5) then '5'
                   when  regexp_substr( code,'[^\-]+',1,6)  then '6'
                   else 'not found' end result
    from t
    CODE     NUM     RESULT
    152-425-3265-8-5623-45     425     2
    152-425-3265-8-5623-45     8     4or if you have 11g you can use regexp_count
    with t as (select  '152-425-3265-8-5623-45' code, '425' num from dual union
                   select  '152-425-3265-8-5623-45' code, '8' num from dual)
    select code, num, regexp_count(regexp_substr(code,'^.*'||num||'.'),'-')
    from tEdited by: pollywog on Jun 24, 2011 7:55 AM

  • Finding the position of the end of a line in a JTextPane

    I'm trying to make a JTextPane which expands horizontally if the text being typed in it reaches the right hand edge. To do this I need to know the position in the Document of the end of the current line.
    I've managed to write a method which expands the JTextPane vertically using getEndPosition() in AbstractDocument.
    There is an endLineAction in the DefaultEditorKit which moves the Caret to the end of the line but I don't want to move the Caret, just find the position of the end of the line. I did have a method before which moved the Caret to the end of the line, stored the position and moved it back but that wasn't suitable.
    I suspected the answer was to do with the View but I can't figure out how the View relates to the JTextPane or Document.
    Can anyone help?

    Well, personally I don't think its a good idea to keep changing the size of the text pane as text is being typed and I doubt the solution will be as easy as you think.
    As you type the text will automatically wrap so it will be a little late trying to change the width after the text has wrapped, which means you would need to increase the width "before" text is typed. But then you have another problem because you don't know how much to increase the width by since a single character could be typed or a string of text could be pasted into the text area (people always forget about pasting when doing stuff like this).
    Also if text is removed you would need to iterate through all the line to find the longest line and reset the width.
    Anyway the only way to know the width would be to play with the modelToView() method. If you want to find the end of the current line then you can use the Element.
    Check out my [Text Utilities|http://www.camick.com/java/blog.html?name=text-utilities] class which might give you some ideas on how to use the Element class and modelToView() method.
    which has example of using the above Class and method that might give you some ideas.

  • How to find the position of view in MM02 transaction for coding BDC?

    Hi Guys,
    Is there any FM or BAPI Available to find the position of the view in MM02 transaction. I tried FM SELECTION_VIEWS_FIND. But getting inconsistent results
    i.e Some materials it is giving correct positions but for others i am getting wrong position. So my BDC is getting failed.
    Thanks in advance.
    Vinod.

    Hi,
    data : i_t133a like t133a occurs 0 with header line,
          ch(1),
           viewno(2) type n.
    clear viewno.
      select * from t133a into corresponding fields of table i_t133a
                    where bilds = '21' and guifu like 'SP%'  .
      loop at i_t133a .
        ch = i_t133a-pstat.
        if mara-vpsta na ch .
          delete i_t133a     .
          continue .
        endif .
      endloop.
      sort i_t133a by guifu ascending .
      loop at i_t133a .
        viewno = viewno + 1 .
        if i_t133a-guifu = 'SP01'.  "FOR BASIC DATA1                CHANGES              ACCORDINGLY REFER TABLE T133A TO FIND VTHE VALUE
          exit .
        endif .
      endloop .
    reward if usefull

  • How can I find the position of a robotic arm with a cFP-CTR card?

    Hello,
    I use a CTR-500 to measure the pulses of 3 encoders.
    The encoders are related to the 3 axis (x,y,z), to which a robotic arm is moving.
    Each encoder has 2 channels (A,B) which go to each pair of Count Inputs of the CTR card.
    When the robotic arm is moving on one axis, the corresponding pair of Count Inputs is increasing, but there is a phase between the one Count Input and the second one. What is more, the Count Inputs do not decrease when the robotic arm is moving to the other direction, but they still increase.
    So, I cannot find easily the position of the robotic arm.
    What I have done, is to try finding the position, by using only one Counter Input for each axis. This means that I use the value of the encoder as a counter, and I calculate the position with some software tricks. But for some reason, it does not work properly.
    I have heard that the method I use is not proper. Instead, I have been told that I must use the phase of the 2 Count Inputs, in order to find the direction to which the robotic arm is moving. But, the Count Inputs of the CTR are augmenting in parallel, when the robotic arm is moving forward or backward.
    How can I find the position of the robotic arm, as it is moving like a CNC ?
    Thank you very much.
    Message Edited by nikosfs on 08-21-2009 12:27 PM

    You don't want to use a cFP-CTR-500 card.  What you have are quadrature signals.  You should be using the cFP-QUAD-510.  It has 4 channels that can handle both the A and B signals of a quadrature encoder.  It has the built in circuitry do determine the phasing of A vs. B to know when to count up vs. count down.

  • Cannot find the ''Positioning Methods'' option on ...

    Hello....I have recently bought the C7-00 and I wanted to test my GPS but I could not find the "Positioning Methods'' option to select the A-GPS, so can anyone help on this.
    Thank you.

    Do you not have a Location app in your Applications Folder ? As CJ mentioned , that is where you set your location methods to on/off. Inside Location you should have 3 sub folders, Landmarks,GPS data and Positioning. Open Positioning and you should be able to change the settings !
    If I have helped at all, a click on the White Star is always appreciated :
    you can also help others by marking 'accept as solution' 

  • My 3 apple products, an imac, a macbook air and a macbook lost their contact with their external hard disks. They were LaCie make. And every time I turn my laptops, I find the positions of the keys on their  keyboards changed.  Why is Apple silent?

    After the latest apple IOS upgrade my 3 apple products, an imac, a macbook air and a macbook, lost their contact with their external hard disks. They were LaCie make. And every time I turn my laptops, I find the positions of the keys on their  keyboards changed.  Why is Apple silent? There are so many people complaining about this issue and expecting Apple to correct this issue that they have created.

    Probably because it's not an Apple issue. I have Lacie EHD's connected to my MBAir and iMac, all work perfectly on Mavericks. In addition I don't have any keyboard issues on any of my Apple products. BTW IOS is only for IOS devices such as iPads, iPods and iPhones, Macs use OS X. The two OS's are seperate  products designed to run on seperate products.

  • Find the position of refrence wbs in tx cj02

    HI friends,
    I need to update one WBS element above the refrence WBS elemnet n tx CJ02 for the project defination.....
    The problem is how do i know the position of the Refrenece WBS elment....
    Please help finding the position of the refrence WBS...
    regards
    kanishak

    Hello,
    You should be able to see it in t-code IM23.
    Try this link also
    [http://rwd.tennessee.edu/content/zpposition_find_a_position/wi/postscript/index.pdf]
    Hope it helps
    Thanks,
    Pavan.

  • 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

  • Is it possible to get the position of a charcter from a string ?

    Hi !
    Is it possible to get the position of a charcter from a string ?
    Example:
    @VAR contains the following text "ABCDEFGHIJKLM"
    I'am seaching for FGH, it start on pos. 6 en ends on pos 8.
    How can I get these numbers 6 and 8 ?
    So, I can use them in the MID(text,start,len) function.
    Thanks!

    Hi Sooraj,
    I'll explain more in detail:
    From a web-service I get a variable called @Spec.
    This variable contains the following:
    "MOTORTYPE[CR]D-QW1234[LF]PART[CR]1234-FRD-X[LF]"
    or
    "MOTORTYPE[CR]ABC[LF]PART[CR]E-435[LF]"
    I need the values behind MOTORTYPE[CR] and behind PART[CR]
    But you’ll see that the positions of these values are different each time.
    If there is a way to get the (start) position of "MOTORTYPE[CR]" or "PART[CR]" and the (end) position of the first "[LF]" behind that,
    then I could use the MID() function to get the correct values.
    The values will be displayed in a table view (between other fields).
    An ABAP-call/function won’t work . . . how should I invoke this within a table column/field object ? (system action ?)

  • Rule to find the Position has SAP ID's or not

    Hi,
    I have requirement where i need to find the whether the position in the org chart contain SAP Id's or not and if the position is not empty then i need to send the mail to position if not i need to send the mail to workflow administrator.
    Please can any one guide me in achieving this functionality.
    regards
    manju

    Hi Arghadip Kar  ,
    thanks for your response
    there is one FM RH_OM_GET_HOLDER_OF_POSITION this will retrieve the user ID's for the given position . so i got the solution .
    i have one more query . i need to find the workflow admin SAP id .is there any FM for that .
    thanks for your response
    Regards
    manju

  • How do I find the position of a single character on a page?

    Hi guys,
    I am developing a PDFEditor, but am having trouble implementing the code which finds the location of glyph characters on a page (in device space). I have read the pdf reference on Text, but do not quite understand it.
    I have worked out the individual character spacings, but I cannot accurately find the location of the first character .
    Here is my current attempt:
    float y = CGPDFPageGetBoxRect([current_page pageReference], kCGPDFCropBox).size.height-current_matrix_position.y;
    float x = current_matrix_position.x;
    float xa = a * x + c * y + e;
    float ya = b * x + d * y + f;
    text_position = [NSValue valueWithCGRect: CGRectMake(xa, ya, 15, d)];
    (where text_position is the location of the start character in device space. a,b,c etc come from the Tm operator.
    current_matrix_position is set as a point (e,f) from the cm operator.)
    This code seems to work with some PDF files:
    But does not work with others:
    (Note there is text in the box above the blue which cannot be disclosed for reasons...)
    Is there something I am missing (like another operator?) or is my formula completely wrong.
    Your help would be greatly appreciated

    Hi Irosenth,
    I have been reading the spec and trying to understand it for several weeks. Unfortunately, I am still confused with how to find the coordinates of the text.
    >> You need to parse the content stream(s) that are associated with the page and
    I have done this. My program finds both the cm operator, the tm operator and the font widths etc. Unfortunately, now that I have all of this information, I am unsure what to do with it.
    How do I properly add these two matricies together? I have looked in the spec which describes it as:
    x' = a * x + c * y + e
    y' = b * x + d * y + f
    I tried this and the results worked on some pages, but not on others (several thousand x coordinates out...). I am finding the ISO 32000-1:2008 very confusing in this section.
    >> manage what you find there
    This is the part I am having major trouble with. Using the coordinate transformation matricies, how can I determine the starting coordinate for the first glyph in a text (BT, ET) on a non-scaled page (so 1 unit = 1 pixel) using the matricies?
    Thanks

  • Need to find the memory address of a buffer or string

    Two basic questions:
    -How does LabVIEW treat the concept of a "buffer"?  Isn't it just a string wired from one block to another?
    -How can I find the address of a memory location or buffer location?
    I am using the Call Shared Library Node to call two functions to unwrap a custom communication protocol packet.  I will be reading packets of information from the serial port and sending them through this unwrapper  The first function expects as the arguments a)the address of the buffer and b)the length (in bytes) of the buffer.  I can measure the length, but am unsure of the address.  I would have just wired the string output of the serial port to the input of the unwrapper, but the unwrapper wants the address of that string/buffer.  The data type of the buffer address that the function expects is "unsigned char*" in C++ which translates to "uInt8" in LabVIEW according to http://zone.ni.com/devzone/cda/tut/p/id/3009.  The second function that is being called writes the unwrapped data to the destination buffer address that I specify as an argument. 
    I located this VI that handles buffering, but am unsure how it would help me, because it doesn't deal with the address issue either (and it used arrays of doubles, not characters or strings which is what the output of the serial port will be).  http://zone.ni.com/devzone/cda/epd/p/id/2499
    Any help would be appreciated.
    Nathan
    Previous related post: Call Library Function Node: Instantiate a class/handle constructors in a C++ Shared Library?

    This question is probably better asked on the LabView forum.  I've never seen this type of question asked here.
    Duncan
    CVI user, even though I also have LabView ;-))

  • Finding the smallest letter in a single alphanumeric string

    How do I find the smallest letter in a single alphanumeric input?
    I already wrote and successfully tested the code that takes an alphanumeric string as input, separates the number from the alphabet, and creates a new alphabetic string. However, I'm unsuccesful in writting the code to find the smallest letter within the alphabetic string. I am almost certain that the easy answer is Arrays.sort, but I unsuccesfully tried writing the code to place the alphabetic string into an array. I researched compareTo, but I do not have another object to compare?! Any suggetsions?

    Ahh flaimbait - I'm sure I'll get criticized for this... but - while we are talking about time-to-market, etc...:
    The most important issue in development is to make sure that you understand the project requirements. The requirements in this situation were:
    Find the smallest character in a string.
    Given that, then any developer that goes through the trouble of looking up the sort APIs, etc... is not helping themselves - all they really needed to do was to write one line of code (as xxxx graciously posted):
    for (int x=0; x<foo.length(); x++) if (foo.charAt(i)<low) low=foo.charAt(x);I absolutely guarantee that any Java programmer could write the above faster than they could figure out how to split a string appart by characters, look up the arraysort API, etc...
    The arraysort functions are EXTREMELY efficient, and I would never suggest that someone re-implement them. The point here is that just because you've got a wrecking ball available, you can still use a hammer to drive a nail.

  • How to find the position of the deicmal place?

    Hi,
    I have a String '-234.45'. I need to determine it decimal place.
    I have try:
      SEARCH '-234.45' FOR '.'.
    but the sy-fdpos is 0.
    How to get the decimal place? Is there other way to get it?
    Please advise.
    Regards,
    Rayden

    Hi,
    see , if this will help you out.
    DATA: text TYPE string VALUE `Roll over Beethoven`,
          pos TYPE i.
    SEARCH text FOR '. .'.
    SEARCH text FOR ` `.
    IF sy-subrc = 0.
      pos = sy-fdpos + 2.
        SEARCH text FOR 'bth' STARTING AT pos
                              ABBREVIATED AND MARK.
    ENDIF.
    cheers,
    Hetal.

Maybe you are looking for

  • How can I send one sms to a group of people?

    how can I send one sms to a group of people?

  • There is no airport option in network

    I have searched to see if i have the airport card and i do. There is a strange problem though and I dont know how to go about it. When I am in system profiler I click on Network and I see all the active services, Airport, Bluetooth DUN, Bluetooth PAN

  • Smartform and date format

    if i need the change the date format according to country how can i do it ( i.e ) I am creating a smartform, the date format i use is normally dd/mm/yyyy if the same smartform is printed in some other country( using format yyyy/mm/dd or any format) i

  • Create form in new window

    there are two pages. There is a table on the first one. The second one can be caused (called) as switch to dialog.and it contains a form of new record creating formed by the same view-object. After creating a new record dialog window closes and an er

  • Compute QTD with Excel's CUBE functions

    Hi, I want to compute QTD Sales using Excel's CUBE functions.  Here are the specifics 1. I created a Pivot Table using PowerPivot and then converted the Pivot Table's cells to Formulas (Pivot Table Options > OLAP > Convert to Formulas) 2. I have two