How to use replace(CharacterSequence, CharacterSequence) in String class

Need simple java program using the following
how to use replace(CharacterSequence, CharacterSequence) in String class
Kindly help

From http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#replace(java.lang.CharSequence,%20java.lang.CharSequence)
replace
public String replace(CharSequence target,
CharSequence replacement)Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".
Parameters:
target - The sequence of char values to be replaced
replacement - The replacement sequence of char values
Returns:
The resulting string
Throws:
NullPointerException - if target or replacement is null.
Since:
1.5

Similar Messages

  • How to use execute immediate for character string value 300

    how to use execute immediate for character string value > 300 , the parameter for this would be passed.
    Case 1: When length = 300
    declare
    str1 varchar2(20) := 'select * from dual';
    str2 varchar2(20) := ' union ';
    result varchar2(300);
    begin
    result := str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || ' ';
    dbms_output.put_line('length : '|| length(result));
    execute immediate result;
    end;
    /SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
    length : 300
    PL/SQL procedure successfully completed.
    Case 2: When length > 300 ( 301)
    SQL> set serveroutput on size 2000;
    declare
    str1 varchar2(20) := 'select * from dual';
    str2 varchar2(20) := ' union ';
    result varchar2(300);
    begin
    result := str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || ' ';
    dbms_output.put_line('length : '|| length(result));
    execute immediate result;
    end;
    /SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 6

    result varchar2(300);Answer shouldn't be here ? In the greater variable ?
    Nicolas.

  • How to use Replacement Path Variables to perform Date Calculations

    Hi Experts,
    Can anyone make me clear about:How to use Replacement Path Variables to perform Date Calculations???????
    Thankyou in advance..
    shankar

    In left panel select the time Dimension
    Then hit new variable in that
    give the Name and Description for the Variable
    In processing by hit Replacement Path
    In reference characterisitcs use Calendar Day...
    As ur intention is to use it for Date
    Then in adjacent tab use
    Replace variable with Query / Variable
    Then u can use Offset length and offset start for controoling the display of your variable.
    Use as single, multiple single, interval, selection option as uwish
    HIt okey
    and you are good to go

  • How to get a char from a String Class?

    How to get a char from a String Class?

    Use charAt(int index), like this for example:
    String s = "Java";
    char c = s.charAt(2);
    System.out.println(c);

  • How to use javasetters and getters in different classes

    how to use setters and getters in different class so that the setvalue in one class is effect in second class for getting

    If i got your question right,
    make sure your classes are in the same package
    make sure your getters are public/protected
    make sure your code calls the setter before calling the getter
    Kind regards

  • How to use replace function?

    Hi,
    How do I replace a string and decode into a grouping? I have something like this:
    Select
    distinct id,decode(SUBSTR(id,1,1),'A','A-D','B','B-D'...from Table
    I want the distinct id for a string called "T to be replaced with XXX and decoded into the the right column. The output should be two columns.
    Any help would be appreciated.

    Hi,
    Is the problem that sometimes you want to test just the first character of id, and other times you need to test more?
    Then use CASE instead of DECODE:
    SELECT  id
    ,       CASE
                WHEN  SUBSTR (id, 1, 1) IN ('A', 'B', 'C')
                OR    SUBSTR (id, 1, 2) = '"D'
                THEN  'A-D'
                ELSE  'OTHER'
            END     AS  column_b
    FROM    table_x;
    {code}
    If you're using Oracle 8 (or later), then never use DECODE.  Always use CASE instead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to use regular expression to find string

    hi,
    who know how to get all digits from the string "Alerts 4520 ( 227550 )  (  98 Available  )" by regular expression, thanks
    br, Andrew

    Liu,
    You can use RegEx as   
    d+
    Whether you are using CL_ABAP_REGEX class then
    report  zars.
    data: regex   type ref to cl_abap_regex,
          matcher type ref to cl_abap_matcher,
          match   type c length 1.
    create object regex exporting pattern = 'd+'
                                  ignore_case = ''.
    matcher = regex->create_matcher( text = 'Test123tes456' ).
    match = matcher->match( ).
    write match
    You can find more details regarding REGEX and POSIX examples here
    http://www.regular-expressions.info/tutorial.html

  • How to use a var as a string

    hello, sorry for my question,
    but I want to use a var as a string:
    I know it is a completely beginners-question, but I didn´t need it until now:
    var zahl = Math.floor((Math.random()*99)+1);
    sym.$("frame")
              .css(
                                  {'background-image':'url("images/zahl.jpg")'
    I tried it with {zahl} and [zahl] but it does not work.
    Help would be great
    Oliver

    Thanks a lot,
    but sorry, I have no sucsess:
    var zahl = Math.floor((Math.random()*99)+1);
    sym.$("frame")
    .css(
                                                                {'background-image':'url("images/" + zahl + ".jpg")'
    here is the whole code again so that you can see if I made a fault.
    THX

  • How to use an instance instead of the class itself

    I am building a program but have a problem.
    My program uses a controller class which instantiates a World-class. In the world class has a Vector I make a Vector in which I place all the elements in the world. (I also made an Element class from which all the objects that I put into this Vector extend.)
    Everything except for some methods in the controller class are declared public. I might need to use static, but I do not know how.
    // CONSTRUCTOR CONTROLLER CLASS
    world = new World ();  // instantiate one and only one world
    world.newElement (new Beamer ("beamer", 20. , 20.));  // use a selfwritten method to add a "Star Trek"-like
                              // beamer to the world. I give it a name and position.
    world.newElement (new Avatar ("avt", "beamer"));  // add an avatar which is "beamed up". so what I do is that I use the beamer for the beginposition of the avatar. However, and this is my problem, in the constructor of Avatar (see below) i need the beamer in world, but my compiler cant find world. I probably need to import my World or controller class, but even then: I do not understand how to use an instance (world is an instance. I cant use the World-class as the class does not contain the beamer element)
    public class Avatar extends Element {
         public Avatar (String n, String beamer){
              name = n;
              posx = world.named("beamer").getPosx; // the selfwritten method named finds the
                // element in the Vector that goes with the name. Any ideas to make this code better are welcome too.
              posy = world.named("beamer").getPosy;
    } Any ideas on how to solve this (common) problem in good coding are most welcome.

    I think you are best off if you use static methods and static fields only in your World class. That way you don't have to instantiate it and everyone has access to its methods. This would be then completely analogous to how you access methods and fields of the well-known class System (e.g. when you use System.out.println). This also has the advantage that you are guaranteed to have only one copy of the World.
    Here is an example of how your World class, Avatar class and main code would look like.
    Main code: (note the use of capital W in the name World, referring to class rather than instance).
    // no need to instantiate World, as we call its static methods only
    World.newElement (new Beamer ("beamer", 20. , 20.));
    World.newElement (new Avatar ("avt", "beamer"));  // add an avatar which is "beamed up". World class: (note the static keyword in front of the vector and the methods)
    public class World {
      private static Vector v;       // static field, only one copy of it ever exists
      public static void newElement(Element e)   // static method, can call without instantiating world
         v.addElement(e);
      public static Element named(String n)  // use to look up elements
         ... some code which goes through v and finds element named "n" ...
         ... return reference to that element ...
    }and finally the Avatar: (again note the use of reference to World as a class rather than instance)
    public class Avatar extends Element {
         public Avatar (String n, String beamer){
              name = n;
              posx = World.named("beamer").getPosx;
              posy = World.named("beamer").getPosy;
    } The above example is how I would implement it when you don't actually need instances of the World class.

  • How to use sed on a literal string containing regex meta characters?

    I want to delete the lines from a file which match an arbitrary literal string.
    The string is contained in a variable, and may itself contain various regex meta characters such as [,],^,$,|, etc
    So, my problem is that sed wants to interpret these meta characters itself. For example:
    x='abc[xyz$'
    sed -i "/$x/d" file
    produces a sed error about the unmatched [, and no doubt it wants to interpret the $ too.
    (Of course, I could try and change the string $x so that every possible regex meta character was escaped with a \, but that seems immensely cumbersome. Also, can't see a way of using single or double quotes cleverly.)
    Sorry if I am being thick about this, but any ideas or alternative methods would be most welcome!

    frostschutz wrote:
    With sed, you have to escape meta characters indivudually. That's just how it works. Of course you could do the escaping using sed as well, by replacing all meta characters (including \ and /) with \character.
    If you want to match strings literally, use a different tool. Or do it in Bash.
    while read line
    do
    [ "$line" != "$x" ] && echo "$line"
    done < file
    In Perl/PCRE instead of escaping indivudually there is \Q...\E but sed does not understand that, and \Q\E does not solve all problems either, if there is a \E in the $x you have to escape it with \E\\E\Q or something like it.
    Thank you for your swift reply. Looks like sed can't be much of a friend in these circumstances!
    Probably will have to go with the Bash file handling method.
    Oh well ...

  • How to use replace function to replace word

    I am trying to write a replace function in which I replace CA with California in an address string.
    I am trying to avoid using regular expression and just use other functions like replace, instr, trim etc.
    But what my main confusion is how do i take care of three cases in which.
    CA can be present with spaces before and after it like.
    - Redwood City, CA 96403
    CA can be present with spaces only before it and after it the string ends.
    - Redwood City, CA
    and I do not want to replace any other CA in the string that is part of other word
    - Blaca Street CA
    ( for example do not replace ca in Blaca)
    or
    - Cardinal Dr CA
    Thanks

    Hi,
    user6287828 wrote:
    ... (only four of these abbreviations need to be replaced)In that case, nesting the functions one inside another won't be too bad. But watch out: this is exactly the kind of requirement that changes over time. You might only need 4 states now, nut next year they might expand the application so that you need all 50 states (plus Puerto Rico, and DC, and ....). In that case, something like MODEL, or a user-defined PL/SQL function, would be better.
    As these are abbreviations these will always be stand alone words and never part of words. And these abbreviation can be at the beginning or end or in between the string.
    And any abbreviation can be present in one column.
    More than one abbreviation can be present in one column
    None of the abbreviations can be present in this column.
    For example
    column
    3251 BLACA ROAD CA 94305
    74 CALDWIN STREET CA
    67 DIGITAL DRIVE NM
    NM UNIVERSITY AVENUE 890
    7645 ROCHESTER NY PARK STREET
    834 GRAND AVENUE ATLANTAPost CREATE TABLE and INSERT statements for the sample data.
    Include all special cases, e.g. more that one abbreviation in the same column.

  • How to use a WebService Model with String Arrays as its input  parameter

    Hi All,
    I am facing the following scenario -
    From WebDynpro Java i need to pass 2 String Arrays to a Webservice.
    The Webservice takes in 2 input String Arrays , say, Str_Arr1[] and Str_Arr2[] and returns a string output , say Str_Return.
    I am consuming this WebService in WebDynpro Java using WEB SERVICE MODEL. (NWDS 04).
    Can you please help out in how to consume a WSModel in WD where the WS requires String Arrays?

    Hi Hajra..
    chec this link...
    http://mail-archives.apache.org/mod_mbox/beehive-commits/200507.mbox/<[email protected]>
    http://www.theserverside.com/tt/articles/article.tss?l=MonsonHaefel-Column2
    Urs GS

  • How to use DB toolkit to input string 255 into ACCESS Database

    I am converting an existing LV-Application from LV5.1.1 w/SQL toolkit to LV7.1 with DB-Conn. Toolkit.  One of the tables in my MS-Access database has a field of TYPE=memo (allows string lengths > 255 characters).  I can't seem to find how to insert this field in the DB-table using the "DB Tools Insert Data.VI" without getting an error.  I have tried converting the input string to a [U8] array, but that also doesn't work.  Just inputing the long string (390-chrs) also gives an error.  Reducing the string length to < 255 allows the new record to be input into the table without errors.  However, I need to be able to input the longer strings for the application to work.
    Does anyone have a solution to this problem.
    Thanks,
    Jim Cardinal

    Something like this
    David
    Message Edited by David Crawford on 01-12-2006 11:53 AM
    Attachments:
    Insert Text to Memo Using DBT.jpg ‏14 KB

  • How to use ora:parseEscapedXML() Function with String Content

    Hello,
    I am receiving a ResponseMessage that returns a string, but the content of the string is actually XML. I have tried to use the ora:parseEscapedXML() function to parses the string (see XML Fragment below) to return structured XML data that can be assigned to typed BPEL variables. The documentation is very limited for this (I've looked in the Developer Guide draft that is available at the OraBPEL site).
    2 customer records from XML literal fragment copied from string result:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <recordset>
    <customer>
    <CustNum>AROUT</CustNum>
    <CustLName>Hardy</CustLName>
    <CustFname>Thomas</CustFname>
    <CustEmail>[email protected]</CustEmail>
    <CustAddress>120 Hanover Sq.</CustAddress>
    <CustCity>London</CustCity>
    <CustRegion></CustRegion>
    <CustPostalCode>WA1 1DP</CustPostalCode>
    <CustCountry>UK</CustCountry>
    </customer>
    <customer>
    <CustNum>BSBEV</CustNum>
    <CustLName>Ashworth</CustLName>
    <CustFname>Victoria</CustFname>
    <CustEmail>Victoria.Ashworth@B&apos;s.com</CustEmail>
    <CustAddress>Fauntleroy Circus</CustAddress>
    <CustCity>London</CustCity>
    <CustRegion></CustRegion>
    <CustPostalCode>EC2 5NT</CustPostalCode>
    <CustCountry>UK</CustCountry>
    </customer>
    The copy rule for assigning CustNum to accountnumber that fails:
    <copy>
    <from expression="ora:parseEscapedXML(bpws:getVariableData('DataService_OutputVariable','invokeSpecMsgReturn','/recordset/customer/CustNum'))"/>
    <to variable="outputVariable" part="payload" query="/client:QueryResult/client:customer/client:accountNumber"/>
    </copy>
    Any help would be greatly appreciated.
    Thanks,
    Sean

    Hello,
    I am attempting to provide more information in order to hopefully get some better guidance here.
    1) The BPEL process I built receives input from a client that is one of city name or region name or postal code or country name and returns a list of customer records with their AccountNumber, LastName, FirstName, Email, Address, City, Region, PostalCode and Country. The BPEL flow invokes a packaged integration Web Service that retuns the records in a string whose content is XML (see XML fragment below).
    2) The string content returned is vaiable based on the input (i.e. city name="London")
    Two customer records from XML literal fragment copied from string result:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <recordset>
    <customer>
    <CustNum>AROUT</CustNum>
    <CustLName>Hardy</CustLName>
    <CustFname>Thomas</CustFname>
    <CustEmail>[email protected]</CustEmail>
    <CustAddress>120 Hanover Sq.</CustAddress>
    <CustCity>London</CustCity>
    <CustRegion></CustRegion>
    <CustPostalCode>WA1 1DP</CustPostalCode>
    <CustCountry>UK</CustCountry>
    </customer>
    <customer>
    <CustNum>BSBEV</CustNum>
    <CustLName>Ashworth</CustLName>
    <CustFname>Victoria</CustFname>
    <CustEmail>Victoria.Ashworth@B&apos;s.com</CustEmail>
    <CustAddress>Fauntleroy Circus</CustAddress>
    <CustCity>London</CustCity>
    <CustRegion></CustRegion>
    <CustPostalCode>EC2 5NT</CustPostalCode>
    <CustCountry>UK</CustCountry>
    </customer>
    I want to <assign> each record from the packaged integration service result (the string whose content is XML) to a complexType variable defined within the BPEL Process WSDL (see example below).
    XML fragment from BPEL WSDL:
    <element name="QueryResult" type="client:recordType"/>>
    <complexType name="recordType">
    <sequence>
    <element name="customer" type="client:customerType" maxOccurs="unbounded"/>
    </sequence>
    </complexType>
    <complexType name="customerType">
    <sequence>
    <element name="accountNumber" type="string"/>
    <element name="lastName" type="string"/>      
    <element name="firstName" type="string"/>
    <element name="email" type="string"/>
    <element name="address" type="string"/>
    <element name="city" type="string"/>
    <element name="region" type="string"/>
    <element name="postalcode" type="string"/>
    <element name="country" type="string"/>
    </sequence>                         
    </complexType>
    I have read through the tutorial and reviwed the XPath Funtion example in the reference (C:\OraBPELPM_1\integration\bpelpm\orabpel\samples\references\XPathFunction), but I am stsill very unclear as to how to handle this. I would appreciate any and all help.
    Thanks,
    Sean

  • How to use Sockets to send/recieve Strings in XML form?

    Hello there to everyone reading my Post !
    I am entering a total new subject in my learning about Java Programming, where I will need to interact with a server, I was wondering If somebody could help me with a Question I have; here it is:
    A server provided me a Socket, (and that is of course an IP address and a Port), And I am supposed to connect to that server using a Java program that connects to servers using a Socket class, then I am supposed to send a String representing a valid XML, and then the server replies me With another String representing a valid XML which I am supposed to store in a String type.
    Is this exact write/read operation possible? If so, could someone please give me some code samples to solve this problem?
    PD: The server Does this operation only: recieve/send Strings. as its called transactional switch.

    Hi ejp, thank you very much for the quickest of replies.
    I am wondering If could you please give me a more detailed source code sample, and the reasons are:
    Well, first I am a newbie. and secondly, and most importantly, I actually can try to send the String that represents the XML, but then...
    I don't have any idea about how to know when my program has finished sending the String. and therefore I wouldn't know where to put the lines of code that start reading the corresponding response String.
    Could you please help me out?
    PD: I've been using DOM to read XMLs. Does DOM Objects also allow to read/write XMLs using Sockets?
    Thanks in advance!

Maybe you are looking for