Searching for the nth occurrence of a substring in a string

I need to search for the 63rd occurrence of a substring <i4> and replace it with <string>. Is there an easy way to do this?
Edited by: sarcasteak on Jun 16, 2009 11:52 AM

nevermind I got it, if anyone was curious
int z = 0;
               while(z<63)
                    index = index2+3;
                    index2 = result.indexOf("<param>", index);
                    resultTest = result.substring(index2);
                    //System.out.println(index2 + " :" + resultTest );
                    z++;
               String originalSubstring = (result.substring(index2);
               String modifiedSubstring = "";
               modifiedSubstring = originalSubstring.replaceFirst("<i4>","<string>" );
               modifiedSubstring = modifiedSubstring.replaceFirst("</i4>","</string>" );
               String fixedString= result.replace(originalSubstring, modifiedSubstring);
               System.out.println(fixedString);Edited by: sarcasteak on Jun 16, 2009 12:32 PM

Similar Messages

  • Find the nth occurrence of a string in a string

    Hi,
    I'm wondering if there is a method like indexOf, but finds the nth occurrence of a string
    public static int occurrence(java.lang.String str,
                                 java.lang.String toFind,
                                 int occurrence)Cheers
    Jonny

    phdk wrote:
    calypso was refering to promes pseudo code.What is promes? I don't understand the word. Sorry!
    I put the global variable 'count' now in the method occurence
    public static int occurence(String str, String toFind, int occurence){
            int origLength = str.length();
            int count = 0;
            while(str.length()>0){
                str = contains(str, toFind, count);
                   if(count == occurence){
                    int length = str.length();;
                    int actualPos = origLength-(length+1);
                    return actualPos;
                   count++;
            return -1;
    public static String contains(String str, String toFind, int count){
            int occurence = str.indexOf(toFind);
            if(occurence != -1 ){
                 count = count+1;
                return str.substring(occurence+1,str.length());
            }else{
                return "";
      }The output is 1 position to high.
    I still don't get which part of the code to replace with this pseudo code: s'.indexOf('toFind', 'index'+1)
    Sorry for being dimwitted!
    Thanks
    jonny

  • Searching for the number in the bigint value...

    HI!
    Could anybody help me with the searching for the number in the bigint value. ex:
    9567423742840 i need to get only the 2nd and 3rd number (56) from this value...
     ^^
    and the same thing with symbols in the strings..
    is there any special function in jsp available for that?
    thanks

    try looking into the String class. There should be a substring or similar function that lets u get only a part of another string. You can convert the int into a string by doing something like new Integer(yourIntValue).toString() and then using that string for your substring function. There may be other ways to do it too, but this is the one I remember off the top of my head.
    Hope it helps
    package com.DJ_Java;

  • Search for the last delimiter in a string

    Hi all,
    My requirement is whenever my length of the string reach 50 characters, the program will search for the last comma delimiter and break line into 2 lines.
    The string format is like this: -
    Input: -
    1234567890123456789012345678901234567890,1234567890
    Expected output: -
    1234567890123456789012345678901234567890,
    1234567890
    Input: -
    1234567890,1234567890,1234567890,1234567890,1234567890
    Expected output: -
    1234567890,1234567890,1234567890,1234567890,
    1234567890
    The difficult part for me is how to search for the last comma delimiter when it reached 50 characters?
      IF strlen(gv_fetxt) > 50.
      .... " do something to break the line into two lines. 
      ENDIF.
    Please help and guide me.
    Thanks in advance.

    Hi,
    Test the following Sample Code it is working according to your Requirements.
    DATA: str1(200),
          str2(200),
          str3(200),
          main_str_len TYPE i,
          sub_str_len TYPE i,
          off_start TYPE i,
          off_end TYPE i.
    DATA: BEGIN OF it_str OCCURS 100,
      str(200),
      END OF it_str.
    str1 = '1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890,1234567890'.
    main_str_len = STRLEN( str1 ).
    off_start = 0.
    off_end = 50.
    WHILE main_str_len GE 0.
      IF main_str_len GT 50.
        CALL FUNCTION 'STRING_REVERSE'
          EXPORTING
            string    = str1+off_start(off_end)
            lang      = 'E'
          IMPORTING
            rstring   = str1+off_start(off_end)
          EXCEPTIONS
            too_small = 1
            OTHERS    = 2.
        REPLACE FIRST OCCURRENCE OF ',' IN str1 WITH '$'.
        CALL FUNCTION 'STRING_REVERSE'
          EXPORTING
            string  = str1+off_start(off_end)
            lang    = 'E'
          IMPORTING
            rstring = str1+off_start(off_end).
        SPLIT: str1 AT '$' INTO str2 str3.
        it_str-str = str2.
        APPEND it_str.
        str1 = str3.
        sub_str_len = STRLEN( str2 ).
      ENDIF.
      IF main_str_len LT 50.
        it_str-str = str1.
        APPEND it_str.
        main_str_len = -1.
      ELSE.
        SUBTRACT: sub_str_len FROM main_str_len.
      ENDIF.
    ENDWHILE.
    LOOP AT it_str.
      WRITE: it_str-str.
    ENDLOOP.
    Please Reply if any Issue,
    Best Regards,
    Faisal

  • I can not store all my Music on my internal Macbook pro hard drive so I am storing it on a large external drive connected to my airport extrem.  How do I get Itunes to search for the music here with out trying to copy it to my laptops hard drive??

    I can not store all my Music on my internal Macbook pro hard drive so I am storing it on a large external drive connected to my airport extreme (2 TB drive plugged into the USB port).  I see the drive on my laptop and I can add and delete files no problem.  How do I get Itunes to search for the music here with out trying to copy it to my laptop's hard drive?  I don't have enough space to do that.

    How did you move the music to the external drive?  What exactly is on the drive?  The entire iTunes folder or only music?  If it is the entire iTunes folder you can do the option+start suggestion earlier.  If you copied only music and did so by dragging it there then you need to delete it again and consolidate/organize it there instead so iTunes tracks the move.  iTunes 12 for Mac: Change where your iTunes files are stored - http://support.apple.com/kb/PH19507

  • Searching for the fields of a table(very very urgent)

    Hi all,
    i am in graet trouble now.i am searching for the fields like
    1)country of origin where the finished good is created.
    2) customer sales order number
    3)customer sales order line number
    i am writing a report for delivery order.in this report i have to refer customer PO & customer SO .
      i mean, my company has a customer ( seagate) & seagate has a customer (let maxtor).initially maxtor will give a PO to seagate then seagate will raise a SO againest maxtor.
       Then seagate will send PO number(of maxtor), PO line number,SO number(seagate), SO line number(seagate) to our company.
       Then i have to write a report for sales order & delivery order.in these reports i have to refer seagate PO number & seagate SO number for reference.
    i got PO number as vbkd-bstkd but not getting any field for reference Sales order.plz advice me on this. it is very very urgent.
    ur idea is highly appreaciated.
    Thank u very much.
    Regards
    pabitra

    check out tables VBAK(sales order header), VBAP(sales items)

  • How can I get a search bar added to my email archives screen to make it easier to search for the right archives folder, Samsung has one so I was surprised to see that I have to scroll up and down to find the right folder?

    How can I get a search bar added to my email archives screen to make it easier to search for the right archives folder, Samsung has one so I was surprised to see that I have to scroll up and down to find the right folder?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    * https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes
    You can modify the pref <b>keyword.URL</b> on the <b>about:config</b> page to use Google's "I'm Feeling Lucky" or Google's "Browse By Name".
    * Google "I'm Feeling Lucky": http://www.google.com/search?btnI=I%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q=
    * Google "Browse by Name": http://www.google.com/search?ie=UTF-8&sourceid=navclient&gfns=1&q=
    * http://kb.mozillazine.org/keyword.URL
    * http://kb.mozillazine.org/Location_Bar_search

  • My Epson XP - 400 will not print wirelessly or via USB. The documents just sits in the print queue while the computer is "searching for the printer".  I set up the printer on the computer and it is connected to the wireless network.

    I'm unable to print wirelessly or connected via USB with my Epson XP-400. The computer continues to say it's searching for the printer even though the printer is set up on the computer, the printer is connected to the wireless network and the USB is plugged into the computer.

    Try resetting your Mac's printing system as shown here:
    http://support.apple.com/kb/PH14141

  • I just made the switch to mac. I am have installed all the new PS6 CC and bridge and I am now trying to add some presets to my  ACR but when I search for the folder to place them it is not there.  From what I researched it says it should be under camera l

    I just made the switch to mac. I am have installed all the new PS6 CC and bridge and I am now trying to add some presets to my  ACR but when I search for the folder to place them it is not there.  From what I researched it says it should be under camera library/application support/adobe/camera raw/settings but I can only get to library/application support/adobe/ and then there are two different camera raw options I have checked both and there are not settings folder. If anyone can help me please thanks

    Apple most likely has the same poor taste that Microsoft does when it come to defaults.  Microsoft likes to hide things like  settings, preset, folders etc from normal users  think the dumb or something else.  If Apple also hide things you will have to  make some system setting changes that will allow Finder to do it job and find it for you.

  • Im trying to download the new itunes so i can use my iphone 5 , however , the new itunes requires Mac OS X 10.6.8 or later and i cant seem to install that onto my imac even after searching for the new update (my imac is currently on 10.5.8.

    .Im trying to download the new itunes so i can use my iphone 5 , however , the new itunes requires Mac OS X 10.6.8 or later and i cant seem to install that onto my imac even after searching for the new update (my imac is currently on 10.5.8.

    You have already seen that you cannot load the new iTunes into your 10.5.8, so as Neil says, you need Snow Leopard (current cost £14).    And you'll probably need to update the disc you buy via the combo update, though that is free.
    As far as the new iTunes is concerned, there's been a certain amount of grumbling so you may want to study the forums before you update.   The main problem has been with album artwork which does not transfer easily.

  • Encountered an error when attempting to open Lightroom for the first time. Went to Lightroom Help and searched for the error "An error occurred when attempting to change modules". Non of the solutions helped. what now?

    Encountered an error when attempting to open Lightroom for the first time. Went to Lightroom Help and searched for the error "An error occurred when attempting to change modules". Non of the solutions helped. What now?

    I am getting this error message as well. I have just downloaded Lightroom recently. I try to click on Lightroom / preferences....and nothing happens. I tried to uninstall and it is greyed out so I can't do that either. Suggestions? Please help?

  • TS1702 i cant download new application on my Iphone everytime i open app store then searching for the application i want to download when i Tap the FREE sign it become half square and never downloaded.

    i cant download new application on my Iphone everytime i open app store then searching for the application i want to download when i Tap the FREE sign it become half square and never downloaded.

    Sometimes this happens because the app won't run on the iOS version of the device you are trying to install it to.  Go to the app store and make sure it will run on iOS 3.1.3 (many only run on iOS 4 or higher).

  • When I am searching for any particular song or album from my shared ITUNES folder, the search is conducted  in the apple store and not on the shared library. How to search for the song in the shared library

    I am using IPAD Mini.When I am searching for any particular song or album from my shared ITUNES folder, the search is conducted  in the apple store and not on the shared library. How to search for the song in the shared library

    Search for shared library is impossible, as far as I know.  Searches supported - are local and internet.

  • BUG: Searching for the word "united" in Contacts returns far too many results

    To recreate this bug:
    1. I open the Contacts App on my iPhone 5 running iOS 6.0.1.
    2. In the search field within the app, I search for the word "united." (For example, if I am trying to located the address book card for United Airlines).
    3. Instead of showing me just the results of companies/people that have the word "united" in their name or notes field, the app returns almost every single one of my contacts as a search result, EVEN THOUGH THESE PEOPLE DO NOT HAVE THE WORD "UNITED" IN THEIR NAME, DESCRIPTION, OR NOTES FIELD.
    I think this might be happening because I have used the iOS feature of connecting my Contact App with Facebook.  Because of this, many of my contacts have the word "unified contact info" in their description. Although this doesn't entirely explain why searching for the word "united" would show "unified contact info" contacts, the Facebook/Contacts App connection may have something to do with this bug.
    Regardless, if I search for the word "united" on my iPhone, the Contact App still returns almost every single contact as a search result, even though the word "united" cannot be found within those contacts.

    I think it is because the system adds "United States of America" to every address by default.
    You need to search using different parameters, for example, "Airlines".

  • As soon as I keep the iPhone (iPhone 5) on the desk the network goes off and when I swipe it then only it starts searching for the network and get it in 30 seconds.  If someone is calling me during that time it says mobile is either switched off or outsid

    As soon as I keep the iPhone (iPhone 5) on the desk the network goes off and when I swipe it then only it starts searching for the network and get it in 30 seconds.
    If someone is calling me during that time it says mobile is either switched off or outside the coverage area.
    Please help

    You may need to force it into recovery mode. See here: https://discussions.apple.com/message/17766427#17766427

Maybe you are looking for

  • Can't Drag in OSX.2.8

    I'm on a 700 MHZ 15" Imac. I cannot drag icons at all. I click on them, and the curser highlights them, but they won't move. I can drag windows just fine, but not icons, or files in Itunes. I know this was a problem associated with 10.2. I tried to f

  • System and sysaux file block corruption

    Errors in file /u01/app/oracle/diag/rdbms/pdent/pdent/trace/pdent_smon_3135.trc: ORA-00604: error occurred at recursive SQL level 1 ORA-01578: ORACLE data block corrupted (file # 1, block # 91607) ORA-01110: data file 1: '/u01/app/oracle/oradata/pden

  • Not able to upload SAP GRC 5.2 rules

    Hi All, We are in the process of performing the Post Installation steps of SAP GRC CC 5.2 While we are trying to import rule set the system is creating/scheduling a background job. In the log there is a warning regarding the URL   WARNING: Cannot get

  • Line Number of a DOM Element

    Hi There, I'm trying to find the originating xml file line number of a DOM element (for purposes of error reporting). It seems that you can somehow use the DOMLocator class, however I can't seem to find any explanation of how to do this. Please could

  • AIP-SSM-10 sensor upgrade

    I have two ASA5520's with ASA-SSM-10 modules which are running Cisco Intrusion Prevention System, Version 6.0(6)E4. These are located at two different sites (one is local and the other remote from where I am based) and so are not running failover. I