Replacing a part of a String with a new String

Hi everybody,
is there a option or a method to replace a part of a String with a String???
I only found the method "replace", but with this method I only can replace a char of the String. I don't need to replace only a char of a String, I have to replace a part of a String.
e.g.:
String str = "Hello you nice world!";
str.replace("nice","wonderfull");   // this won't work, because I can't replace a String with the method "replace"
                                    // with this method I'm only able to replace charsDoes anyone know some method like I need???
Thanks for your time on answering my question!!
king regards
IceCube-D

do check java 1.4 api, I think there is a method in it, however for jdk1.3 you can use
private static String replace(String str, String word,String word2) {
     if(str==null || word==null || word2 == null ||
           word.equals("") || word2.equals("") || str.equals("")) {
          return str;
     StringBuffer buff = new StringBuffer(str);
     int lastPosition = 0;
     while(lastPosition>-1) {
          int startIndex = str.indexOf(word,lastPosition);
          if(startIndex==-1) {
               break;
          int len = word.length();
          buff.delete(startIndex,startIndex+len);
          char[] charArray = word2.toCharArray();
          buff.insert(startIndex,charArray);
          str = buff.toString();
          int len2 = startIndex+word2.length();
          lastPosition = str.indexOf(word,len2);
     return buff.toString();

Similar Messages

  • I'd like to use Organiser part of Element 9 with my new Photoshop CC to manage my photographs, is this possible ?

    I'd like to use Organiser part of Element 9 with my new Photoshop CC to manage my photographs, is this possible ?. Photoshop CC seems to offer only the photo editing functions, with organiser I  can sort, tag and organise all of the photographs.

    Most subscribers will use Lightroom for organizing their photos. Lightroom will automatically recognize an installed copy of Photoshop CC. But you could use Organizer. Simply select a thumbnail  and then from the Organizer menu bar click:
    Edit >> Edit with Photoshop or use Ctrl+H

  • My Mac operating system is OSX 10.4.11 and I "replaced" my older version of Firefox with a newer one that does not open with my system. Can you send me an older version of Firefox? Thanks!

    My Mac operating system is OSX 10.4.11 and I "replaced" my older version of Firefox with a newer one that does not open with my system. Can you send me an older version of Firefox? Thanks!

    You can get Firefox 3.6.20 from here. <br />
    http://www.mozilla.com/en-US/firefox/all-older.html

  • Replace AR Credit Memo Request Workflow with a new Custom Workflow

    Hello friends,
    We have a business requirement to replace the AR Credit Memo Request Workflow with a new Custom Workflow whenever an Invoice is disputed (Oracle Advanced Collections).
    The Credit Memo Request workflow is being launched within the Oracle API arw_cmreq_cover. We thought of an approach wherein the Oracle form IEXINDTL.fmb can be renamed and the Custom workflow to be called in the WHEN-BUTTON-PRESSED trigger on Dispute Button instead of calling the program Unit IEXINDTL_CONTROL.DISPUTE (as in standard form) which inturn calls several API's and hence the AR Credit Memo Request Workflow. But this would override the other standard processes being carried out in these API's. Our requirement is to only replace the AR Credit Memo Request Workflow and not to override the other standard processes.
    Does anyone have come across the similar requirement? Please let us know your inputs.
    Thanks in Advance !

    I ran across the same error today. Since it's been over a month, I assume you've fixed it already or decided you didn't need it at all? What was your fix?
    For me, I noted that in the sample directory, a similar "createView" call (in End User Anonymous Enrollment) also includes this argument:
    <Argument name='viewId' value='User'/>
    When I added that to my createView call, the "Missing view id" error went away, and the user are gets created.
    I'm not entirely comfortable with the value specified, though; seems like view IDs should be more unique. I would have thought it should have been something like this instead:
    <Argument name='viewId' value='User:$(accountId)'/>

  • Replace an old ipod on itunes with a new ipod

    I want to buy a new ipod. But I already have hooked up 5 different ipods to my computer which I thought was the limit. Is there a way for me to replace my old ipod with a new one?

    The 5 limit you are referring to is a limit of 5 authorized computers to play purchases. You can use as many iPods as you want.

  • Replacing all occurrences of characters in a string with one new character?

    Hi there,
    I'm looking for a way that I could replace all occurrences of a set of specific characters with just one new character for each occurrence.
    For example if I have a string which is "word1...word2.......word3....word4............word5" how would I be able to replace this with just one character such as ":" for each set of "." so that it would essentially appear like this "word1:word2:word3:word4:word5"
    If I just use replace(".", ":") I am left with "word1:::word2:::::::word4::::word5::::::::::::"
    So therefore I'm guessing this would require the use of replaceAll() maybe? but I'm not really very familiar with how regular expressions work and how this would be accomplished using them.
    Any help would be greatly appreciated :) Thanks.

    Yes, but "." means any character, so ".\+" means "any character repeated more than once". If you just mean a full stop ("period" for you Americans :p) you should use "\.+" as your regular expression, but remember that for Java you need a '\' escape to recognise '\' as '\', so in code you'd actually type your regex as:
    "\\.+"Here's an example of one way to do it:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Test {
        public static void main(String[] args) {
           String string = "example1.......example2...example3.....example4";
         Pattern pattern = Pattern.compile("\\.+");
         Matcher stringMatcher = pattern.matcher(string);
         string = stringMatcher.replaceAll(":");
         System.out.println(string);
    }Edited by: JohnGraham on Oct 24, 2008 5:19 AM
    Edited by: JohnGraham on Oct 24, 2008 5:22 AM

  • How do I replace my old internal hard drive with a new one?

    I just ordered a new 1TB hard drive to replace my very small hard drive in my 17" MacBook Pro.
    I've looked around at some of the discussions and apparently I need to format the new hard drive first.  I am not so great with this techy stuff.  Can someone briefly help me and explain exactly how I am supposed to do this?  Like I take my old hard drive out first put the new one in.... format it.  Take it out put the old one in... somehow copy it... agh confused...
    Help?  Thanks.

    If you have a time machine back up of your current drive you can do this
    Shut down your computer, install the new drive. While the computer is off plug in the external hard drive that you have your time machine back up on. Hold Option key while the computer turnes on, let go of the option key once you get a grey screen. Shortly after you'll see  a list of bootable drives, select the one that has your time machine back up on it and boot into that drive.
    From there go into disk utility, format your new drive too, osx extended journaled ( I think, double check that, its been awhile since ive had to do this), hit format
    Exit disk utility and then you can use time machine to copy all your exisit data to the new hhd and then your pretty much done.
    There is also a program called Carbon Cloner that will do esentially the same thing however I've never uesed it.

  • How do I replace my AirPort Extreme Time Capsule with a new one?

    I'm having issues setting up my new time capsule. I currently have the first gen time capsule and I'm having difficulty setting up the new one. The system is not recognizing the new one. What do I need to do??

    You must use the latest utility 6.3 in the lion/mountain lion OS.. You must turn on ipv6 local link.
    http://support.apple.com/kb/TS4597
    If you are trying to do it over wireless.. reset to factory and start over.. the new unit must be at factory settings to work with the utility.
    IMHO use ethernet.. it is far superior.. You don't have to use it once it is setup.
    But the setup will go easier with hard wired connection.

  • I can't replace an old version of Firefox with a new one that I just downloaded. It says I don't have permissions to do so, and the old version can't trashed.

    I've downloaded the new version, and when I go to drag the Firefox icon into the Applications folder, I'm prompted to replace the old version. When I do, it says, "The operation can’t be completed because you don’t have permission to modify 'Firefox'." I've looked everywhere, and every help forum says to just drag Firefox into the Trash. I've tried that, and it says that Firefox can't be trashed. I don't know if this means anything or not, but there is a small lock in the bottom left of the Firefox icon in my dock.

    Try to drag the current Firefox application to the trash if you can't replace it.

  • I want to replace my 1st generation time capsule with the new ac time capsule. What might I use the old 1st generation time capsule for

    What use would there be for the 1st generation time capsule if I bought a new ac time capsule?

    I just bought hte new ac time capsule (TC), and was using the 1st generation one at home.
    => I use now the old TC as an wifi extender and as a shared hard disk for family
    => the new TC is used with Time Machine for encrypted backup and first high speed network

  • Replace Role 13200137 (finding 'support team') with a new role

    Hi,
    I copied the role 'CRM_DNO_1' to 'z_crm_dno_1'. All Datas was copied exept the datas in the section 'responsibitity' - is this ok?
    the new role 'z_crm_dno_1' has now the number 90100005. where can I change the role number form the standard-role CRM_DNO_1 13200137 to 90100005?
    and where in the new role can I modify the name of the FB CRM_DNO_READ_PARTNER_WFRULE to my new FB Z_CRM_DNO_READ_PARTNER_WFRULE ?
    thx in advance,
    kind regards
    Franz

    Hi, Stéphane!
    I copied the Role CRM_DNO_1  by doing this:
    o     Call Transaction PFAC_RESPO
    o     Type in u201A13200137u2018 into Field u201ARuleu2018
    o     Click on Icon u201ACopyu2018
    o     Type in  u201AZ_CRM_DNO_1u2018 in Block u201ATou2018 Field u201AObject abbreviationu2018 and Text
    o     Complete the u201ACopyu2018-prcess with a click on Icon u201ACopyu2018 > the System created the new RuleNo u201A90100005u2018 (and added some u201AResponsibilitiesu2018 and new fields in the u201AContaineru2018)
    I copied the FB CRM_DNO_READ_PARTNER_WFRULE to Z_ CRM_DNO_READ_PARTNER_WFRULE (and the required definitions and form-routine into a new Functiongroup Z_ CRM_DNO_TOOLS)
    for prepareing the new fields in the Container)
    Then
    transaction code SPPFCADM --> select CRM_ORDER --> Define actions and action profile
    selection of u201A SLFN0001_STANDARD     Support Desk Message Action Profileu2018 and click u201AAction Definitonu2018
    click u201Anew entriesu2018
    Setu2018 Z_ Z_SLFN0001_STANDARD_FIND_PARTu2018 (similar to u201ASLFN0001_STANDARD_FIND_PARTu2018)
    Set all values on this screen in tab u201Aaction definitonu2018 similar to u201ASLFN0001_STANDARD_FIND_PARTu2018
    Click to u201Aprocessing typesu2018
    Click to u201Anew entriesu2018
    Select u201AMethod Callu2018 for u201APermitted Processing Types of Actionu2018
    Click to u201Achange definitionu2018
    Click to u201Acreateu2018
    Similar to u201ASLFN0001_STANDARD_FIND_PARTu2018 create two u201AExpressionsu2018, one with u201ARuleu2018 but with u201Ainitial valueu2018 u201A90100005u2018 instaed of u201A13200137,
      and the second with u201APartner_FCTu2018
    now my questions:
    Is this what I  mentioned above ok?
    But which Method in on the screen u201Aprocessing types -> setting method callu2018 do I need?
    And where is the linkage betweet the role and my new FB?
    Hope I didu2019t annoy you to much!
    Thanks in advande,
    Franz

  • How do I replace my old external hard drive with a new larger external hard drive and move my music so itunes can find it?

    How do I move music from an old external hard drive to a new external hard drive and have itunes find it? 

    If you have a time machine back up of your current drive you can do this
    Shut down your computer, install the new drive. While the computer is off plug in the external hard drive that you have your time machine back up on. Hold Option key while the computer turnes on, let go of the option key once you get a grey screen. Shortly after you'll see  a list of bootable drives, select the one that has your time machine back up on it and boot into that drive.
    From there go into disk utility, format your new drive too, osx extended journaled ( I think, double check that, its been awhile since ive had to do this), hit format
    Exit disk utility and then you can use time machine to copy all your exisit data to the new hhd and then your pretty much done.
    There is also a program called Carbon Cloner that will do esentially the same thing however I've never uesed it.

  • Need help on how to replace existing Status Profile on IO with a new one

    Hi there, I have created a new status profile SV00001 assigned it to my order types and everything is OK for newly created internal orders. But I would also like the old internal orders which currently have status profile 0000002 to be assgned to this new status profile. Any idea on the best way to achieve this? Thanks!

    Hi,
    It is not possible to change the profile once any status value has been activated. Changing the profile could introduce inconsistent status settings as the new profile would not necessarly contain the status values of the older profile. There would then be a mismatch between active/deactivated status values and what status values were defined in the new profile.
    It is just not possible to allow change for that reason.
    -Paul

  • Amzing.. just replace my 7 year old imac with a new 27 "iMac  and   last night realised there is no built in drive for DVD., Amzing.. just replace my 7 year old imac with a new 27 "iMac and last night realised there is no built in drive for DVD.

    Amazing the new 27 inch I mac has no built in dVD player. Bit like buying a brand new car and finding it doesnt have any doors.

    Great analogy - particularly applicable to folks who would buy a new car without looking at it, never mind taking it for a test drive.

  • Stepping through a query result set, replacing one string with another.

    I want to write a function that replaces the occurance of a string with another different string.  I need it to be a CF fuction that is callable from another CF function.  I want to "hand" this function an SQL statement (a string) like this:   (Please note, don't bother commenting that "there are eaiser ways to write this SQL..., I've made this simple example to get to the point where I need help.  I have to use a "sub_optimal" SQL syntax just to demonstrate the situation)
    Here is the string I want to pass to the function:
    SELECT
      [VERYLONGTABLENAME].FIRST_NAME,
      [VERYLONGTABLENAME].LAST_NAME,
      [VERYLONGTABLENAME].ADDRESSS
    FROM
      LONGTABLENAME [VERYLONGTABLENAME]
    Here is the contents of the ABRV table:
    TBL_NM,  ABRV    <!--- Header row--->
    VERYLONGTABLENAME, VLTN
    SOMEWHATLONGTALBENAME, SLTN
    MYTABLENAME, MTN
    ATABLENAME, ATN
    The function will return the original string, but with the abreviations in place of the long table names, example:
    SELECT
      VLTN.FIRST_NAME,
      VLTN.LAST_NAME,
      VLTN.ADDRESSS
    FROM
      LONGTABLENAME VLTN
    Notice that only the table names surrounded by brackets and that match a value in the ABRV table have been replaced.  The LONGTABLENAME immediately following the FROM is left as is.
    Now, here is my dum amatuer attempt at writing said function:  Please look at the comment lines for where I need help.
          <cffunction name="AbrvTblNms" output="false" access="remote" returntype="string" >
            <cfargument name="txt" type="string" required="true" />
            <cfset var qAbrvs="">  <!--- variable to hold the query results --->
            <cfset var output_str="#txt#">  <!--- I'm creating a local variable so I can manipulate the data handed in by the TXT parameter.  Is this necessary or can I just use the txt parameter? --->
            <cfquery name="qAbrvs" datasource="cfBAA_odbc" result="rsltAbrvs">
                SELECT TBL_NM, ABRV FROM BAA_TBL_ABRV ORDER BY 1
            </cfquery>
         <!--- I'm assuming that at this point the query has run and there are records in the result set --->
        <cfloop index="idx_str" list="#qAbrvs#">      <!--- Is this correct?  I think not. --->
        <cfset output_str = Replace(output_str, "#idx_str#", )  <!--- Is this correct?  I think not. --->
        </cfloop>               <!--- What am I looping on?  What is the index? How do I do the string replacement? --->
            <!--- The chunck below is a parital listing from my Delphi Object Pascal function that does the same thing
                   I need to know how to write this part in CF9
          while not Eof do
            begin
              s := StringReplace(s, '[' +FieldByName('TBL_NM').AsString + ']', FieldByName('ABRV').AsString, [rfReplaceAll]);
              Next;
            end;
            --->
        <cfreturn output_txt>
        </cffunction>
    I'm mainly struggling with syntax here.  I know what I want to happen, I know how to make it happen in another programming language, just not CF9.  Thanks for any help you can provide.

    RedOctober57 wrote:...
    Thanks for any help you can provide.
    One:
    <cfset var output_str="#txt#">  <!--- I'm creating a local
    variable so I can manipulate the data handed in by the TXT parameter.
    Is this necessary or can I just use the txt parameter? --->
    No you do not need to create a local variable that is a copy of the arguments variable as the arguments scope is already local to the function, but you do not properly reference the arguments scope, so you leave yourself open to using a 'txt' variable in another scope.  Thus the better practice would be to reference "arguments.txt" where you need to.
    Two:
    I know what I want to happen, I know how to make it happen in another programming language, just not CF9.
    Then a better start would be to descirbe what you want to happen and give a simple example in the other programming language.  Most of us are muti-lingual and can parse out clear and clean code in just about any syntax.
    Three:
    <cfloop index="idx_str" list="#qAbrvs#">      <!--- Is this correct?  I think not. --->
    I think you want to be looping over your "qAbrvs" record set returned by your earlier query, maybe.
    <cfloop query="qAbrvs">
    Four:
    <cfset output_str = Replace(output_str, "#idx_str#", )  <!--- Is this correct?  I think not. --->
    Continuing on that assumption I would guess you want to replace each instance of the long string with the short string form that record set.
    <cfset output_str = Replace(output_str,qAbrs.TBLNM,qAbrs.ABRV,"ALL")>
    Five:
    </cfloop>               <!--- What am I looping on?  What is the index? How do I do the string replacement? --->
    If this is true, then you are looping over the record set of tablenames and abreviations that you want to replace in the string.

Maybe you are looking for