How to replace string

Hi Experts,
This is not jdeveloper question, but still i am asking, becoz i dont know other blogs......:(
I want to replace one string, i am using StringUtils.replace(originalString,searchString,replacedString) everthing is working fine but if my
originalString:"1,65.0000,65.0000,1,MMMF,Current,SHTC,"
searchString:originalString[3]-- 1
replacedString: testing
so finally string is : :"testing,65.0000,65.0000,testing,MMMF,Current,SHTC," -- its wrong because i thought to change only 3rd element from the array, but the same 1 is there in both positions i tried with
StringUtils.replace(originalString,searchString,replacedString,occurences) when i put occurences as 1 then its changing 0th element.
can any one suggest me how to resolve this issue.
sorry if this question causes inconvinence to any one.
Any inputs could be highly appreciate.
Edited by: user642703 on Feb 29, 2012 9:52 PM

http://commons.apache.org/ is probably the best place for you to look around (they have a mailing list) - I assume you are using their StringUtils

Similar Messages

  • How to replace string in existing pdf using pdfbox?

    My requirement:
    Your loan amount @loanamount is approved.
    I wanted to replace @loanamount to 5,00,000. If i try with pdfbox api,i am not able to replace. i am getting empty space in pdf.
    If i use same api and if try to replace @loanamount to abcd. now its replacing
    replaceFirst("@loanamount","5,00,00"); - not able to replace. getting empty content in pdf
    public void replaceString()
    PDDocument doc = null;
    try {     
    doc = PDDocument.load("D:/DOCS/Letter.pdf"); //Input PDF File Name
    List pages = doc.getDocumentCatalog().getAllPages();
    for (int i = 0; i < pages.size(); i++)
    PDPage page = (PDPage) pages.get(i);
    PDStream contents = page.getContents();
    PDFStreamParser parser = new PDFStreamParser(contents.getStream());
    parser.parse();
    List tokens = parser.getTokens();
    for (int j = 0; j < tokens.size(); j++)
    Object next = tokens.get(j);
    if (next instanceof PDFOperator)
    PDFOperator op = (PDFOperator) next;
    // Tj and TJ are the two operators that display strings in a PDF
    if (op.getOperation().equals("Tj"))
    // Tj takes one operator and that is the string
    // to display so lets update that operator
    COSString previous = (COSString) tokens.get(j - 1);
    System.out.println("COSString::"+previous);
    String string = previous.getString();
    string = string.replaceFirst("@loanamount", "5,00,000");
    //Word you want to change. Currently this code changes word "Solr" to "Solr123"
    previous.reset();
    previous.append(string.getBytes());
    PDStream updatedStream = new PDStream(doc);
    OutputStream out = updatedStream.createOutputStream();
    ContentStreamWriter tokenWriter = new ContentStreamWriter(out);
    tokenWriter.writeTokens(tokens);
    System.out.println("updatedStream::"+updatedStream.getInputStreamAsString());
    page.setContents(updatedStream);
    //setItem(COSName.CONTENTS,updatedStream);
    doc.save("D:/DOCS/loanamt_filled.pdf"); //Output file name
    sample content in pdf:
    Dear ABC,
    Your loan amount @loanamount is approved.
    Regards,
    DEF
    Output:Your loan amount is approved.
    I m getting empty spaces instead of @loanamount
    Could anyone help me out ?
    Please suggest me java open source api to replace caption or content in existing pdf.
    Thanks in advance...

    Tom
    To answer your original question, I know of now easy way of processing your clips and replacing the existing ones already edited.
    If I have this right you have your sequence fully edited?
    There is a workaround, messy and time consuming but it will not spoil the video element of the sequence.
    Process: -
    Drag the audio for each clip so that it is on a track with space at either end of it.
    Unlink each clip.
    For every audio clip extend each audio's head and tail
    Then use the edit in Audition link
    The clips are individually processed
    Then you can go back adjust the head and tail to what you want and fade out and in as you wish.
    I'd manually fade each clip rather than add an audio transition
    Take care not to alter the video clips at any time or you will go out of sync
    Hope this helps
    Col

  • How to replace string with image( Say Smiley).........????

    Hello To All Experts !!
    I wanna looking for some help in displaying image in my text area when should i type ":)" in text field.....
    I got some program through forums....
    import java.util.*;
    import javax.swing.ImageIcon;
    public class TokenizeSmiley {
        private static final HashMap SMILEYS;
        static {
            SMILEYS = new HashMap();
            SMILEYS.put(":)", new ImageIcon("images/1.gif"));
            SMILEYS.put(";)", "<wink>");
        public static void main(String[] args) {
            String text = "Hello!! :) How are you ;)";
            StringTokenizer st = new StringTokenizer(text);
            String token;
            while (st.hasMoreTokens()) {
                token = st.nextToken();
                if (SMILEYS.containsKey(token))
                    token = (String)SMILEYS.get(token);
                System.out.print(token + " ");
    }but it is showing <smile> and <wink> as it is given...i tried to give path of image ...but it is nt fetching then also.....
    Plz help in this....
    Message was edited by:
    Damz@del

    So your data is stored in XML. So what? You haven't asked a question about the XML or how to format it or how to access it. You asked a question that had nothing to do with XML at all. It's as if you said "My data is stored on a Windows computer so I will call Microsoft's support line to ask them this question."
    And I can't even suggest a suitable forum because a "text area" could be an AWT component or an HTML component. But I do suggest you ask in the right place.

  • How to replace string with image( Say Emoticons )??

    Hello Friends !!
    I am working on chat messenger and want some help in "How to access Emoticons when somebody typed :), ;), :)) and many more strings.....?"
    Is there any sample code to do that job or any function to perform such task??
    Thanks in Advance....

    use event listener... found match, load image instead of text on the fly.

  • How to replace string containing special characters by another string

    Hi all,
    I have to Search for a pattern and replace it by a substitute pattern [Eg: Replace methodOrig (a,b) with  SessTime = getSessionParameter(time);  methodNew(a,b,SessTime) ] in files.
    i tried this using replace(),but it din't work since string1 contains special characters.
    can anyone help me asap.
    thanks in advance.

    Double-post: http://forum.java.sun.com/thread.jspa?threadID=599211&tstart=0

  • How to replace double quotes with a single quote in a string ?

    Hi All:
    Can some one tell me how to replace double Quote (") in a string with a single quote (') ? I tried to use REPLACE function, but I couldn;t get it worked.
    My example is SELECT REPLACE('STN. "A"', '"', ''') FROM Dual --This one throws an error
    Thanks,
    Dima.

    Whether it is maybe not the more comfortable way, I like the quoting capabitlity from 10g :
    SQL> SELECT REPLACE('STN. "A"', '"', q'(')') FROM Dual;
    REPLACE(
    STN. 'A'{code}
    Nicoals.                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to replace multiple occurences of space in a string to a single space?

    How to replace multiple occurences of space in a string to a single space?

    Hi,
    try this code.
    data : string1(50) type c,
              flag(1) type c,
              dummy(50) type c,
              i type i,
              len type i.
    string1 = 'HI  READ    THIS'.
    len = strlen( string1 ).
    do len times.
    if string1+i(1) = ' '.
    flag = 'X'.
    else.
    if flag = 'X'.
    concatenate dummy string1+i(1) into dummy separated by space.
    clear flag.
    else.
    concatenate dummy string1+i(1) into dummy.
    endif.
    endif.
    i = i + 1.
    enddo.
    write : / string1.
    write : / dummy.

  • How to replace a character in a string with blank space.

    Hi,
    How to replace a character in a string with blank space.
    Note:
    I have to change string  CL_DS_1===========CM01 to CL_DS_1               CM01.
    i.e) I have to replace '=' with ' '.
    I have already tried with <b>REPLACE ALL OCCURRENCES OF '=' IN temp_fill_string WITH ' '</b>
    Its not working.

    Hi,
    Try with this..
    call method textedit- >replace_all
      exporting
        case_sensitive_mode = case_sensitive_mode
        replace_string = replace_string
        search_string = search_string
        whole_word_mode = whole_word_mode
      changing
        counter = counter
      exceptions
        error_cntl_call_method = 1
        invalid_parameter = 2.
    <b>Parameters</b>      <b> Description</b>    <b> Possible values</b>
    case_sensitive_mode    Upper-/lowercase       false Do not observe (default value)
                                                                       true  Observe
    replace_string                Text to replace the 
                                         occurrences of
                                         SEARCH_STRING
    search_string                 Text to be replaced
    whole_word_mode          Only replace whole words   false Find whole words and                                                                               
    parts of words (default                                                                               
    value)
                                                                               true  Only find whole words
    counter                         Return value specifying how
                                        many times the search string
                                        was replaced
    Regards,
      Jayaram...

  • How to replace in a String

    I really want to know how to replace " in a String with replaceAll()
    I want to replace " with \"
    Unortunately I am not able to do it with :
    xml = xml.replaceAll("\"", "\\\"");Can u please suggest something
    thanks

    public class Test {
    public static void main(String[] args) {
       System.out.println("abc>def".replaceAll(">","\"+"));
    }Output:
    abc"+def

  • How to replace the char values into numeric in my string?

    Hi Friends,
    I would like to Replace the Charecter values with numeric value in my string.
    Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
    I mean How to replace the char values into numeric in my string?
    Thanks,
    Sridhar

    Hi Sridhar,
    I would like to Replace the Charecter values with numeric value in my string.
    Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
    So, if i understand you correctly, you want to replace all characters in a string with 9 as in the above example, irrespective of position of the character, if so try with the below code.
    DATA: l_str TYPE string.
    l_str = 'ASKHSIUDNSBDKJSDH124312431243124saasdfsf'.
    REPLACE ALL OCCURRENCES OF REGEX '\D' IN l_str WITH '9'.
    IF sy-subrc EQ 0.
      WRITE: l_str. "Result will be 9999999999999999912431243124312499999999
    ENDIF.
    Regards,
    Chen
    Edited by: Chen K V on Jun 13, 2011 12:36 PM

  • Flash Charts - How to manipulate the #data# replacement string in XML

    I have a problem with the XML file for a flash chart. I am trying to display a 2dColumn chart of an SQL query with the general form:
    select null link, x as name, sum(y) as value from z group by (x);
    this generates multiple rows, which are displayed as a bar in the chart. So far so good. The problem is, that each row is defined as a block in the chart, but only one name entry is created "value", which is displayed in the legend of the chart.
    I can display the block names on the x-axis of the chart, however, I can't rotate them, so that they don't overlap in the display, which I would be able to do with names. I assume, that the blocks are defined in the #data# replacement string of the XML file. I would like to change the generated XML replacement string from the SQL to make each row selected a different name, and only have one block ("value").
    What would be the easiest way to achieve this?

    user587996,
    There's no way to manipulate the #data# replacement directly, but you could generate your own XML (see Re: Apex changing nulls to zeroes when creating Flash Charts for one way to do it).
    When you say "I can't rotate them, so that they don't overlap in the display" -- have you tried the Labels Rotation chart attribute, or is that not working?
    - Marco

  • How to use String.replaceAll(String regex, String replacement)?

    hi,
    I'd like to use the String.replaceAll call to replace all occurrences of a pattern in a string with a string inputted from the user.
    The problem is that replaceAll seems process the replacement string first. For example, the code below won't work
    public class StringTest {
         public static void main(String [] arg) throws Exception {
              String input = "oooIoooIooo";
              input=input.replaceAll("I","\\");
              System.out.println(input);
    }So the only option seems to be to manually process the user input string into a form that can be accepted by String.replaceAll?
    The only thing I can find from looking through the API is that you'd need to convert each backslash to a double-backslash?
    is this the right thing to be doing?
    thanks,
    asjf

    just to clarify, at the moment I think the solution is to do this
    public class StringTest {
         public static void main(String [] arg) throws Exception {
              String input = "oooIoooIooo";
              String raw = "\\";
              input=input.replaceAll("I",raw.replaceAll("\\\\","\\\\\\\\"));
              System.out.println(input);
    }

  • How do i do a Advance replace string logic?

    Hi all,
    I have an issue on writing a logic to replace a string in a sentence
    Suppose i fill in 3 input
    1st input - *"The Name contains 'Test1' and 'Test2' and this is it"*
    2nd input - *"The Name contains \"{mercName1}\" and \"{mercName2}\" and this is it"*
    3rd input - *"(\"{mercName1}\")) and (\"{mercName2}\"))"*
    The logic will compare 1st input and 2nd input, then replace mercName1/mercName2, and the output should be like this
    output - *("'Test1'")) and ("'Test2'"))*
    Currently i have make it works and here's the logic
    public class ReplaceString {
         private String getRuleMap(String strRuleC_DRL, String strRuleM_Desc, String strRuleM_Map) {
              String[] strRuleC_DRL_split = strRuleC_DRL.split(" ");
              String[] strRuleM_Desc_split = strRuleM_Desc.split(" ");
              Map compareMap = new HashMap();
              if(strRuleC_DRL_split.length == strRuleM_Desc_split.length) {
                   for(int x=0; x<strRuleC_DRL_split.length; x++) {
                        int compare = strRuleC_DRL_split[x].compareTo(strRuleM_Desc_split[x]);
                        if(compare != 0) {
                             compareMap.put(strRuleM_Desc_split[x].replaceAll("\"", ""), strRuleC_DRL_split[x].replaceAll("\"", ""));
              if(!compareMap.isEmpty()) {
                   Iterator keyIter = compareMap.keySet().iterator();
                   while(keyIter.hasNext()) {
                        String theKey = keyIter.next().toString();
                        String theValue = compareMap.get(theKey).toString();
                        if(strRuleM_Map.indexOf(theKey) > 0) {
                             strRuleM_Map = this.replace(strRuleM_Map, theKey, theValue);
              return strRuleM_Map;
         private String replace(String source, String pattern, String replace) {
              if (source!=null) {
                   final int len = pattern.length();
                   StringBuffer sb = new StringBuffer();
                   int found = -1;
                   int start = 0;
                   while( (found = source.indexOf(pattern, start) ) != -1) {
                        sb.append(source.substring(start, found));
                        sb.append(replace);
                        start = found + len;
                   sb.append(source.substring(start));
                   return sb.toString();
              else return "";
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              ReplaceString rs = new ReplaceString();
              System.out.println(rs.getRuleMap("The Name contains 'Test1' and 'Test2' and this is it", "The Name contains \"{mercName1}\" and \"{mercName2}\" and this is it", "(\"{mercName1}\")) and (\"{mercName2}\"))"));
    }Now, here's the problem, when i key in
    input - *"The Name contains 'Test1 and Test2' and 'Test3 and Test 4' and this is it"*
    i expect the output should be
    output - *("'Test1 and Test2'")) and ("'Test3 and Test4'"))*
    but i hit problem cause the string compare is only 1 to 1
    Is there any advice? Thanks

    You could try to use regular expressions?

  • How to replace NULL values from main table

    Dear all,
    I like to remove the NULL values from a main table field. Or the question is how to replace any part of the string field in MDM repository main table field.
    e.g.   I have a middle name field partly the value is NULL in some hundreds of records, I like to replace NULL values with Space
    any recommendation.
    Regards,
    Naeem

    Hi Naeem,
    You can try using Workflows for automatically replacing NULLs with any specific value.
    What you can do is: Create a workflow and set trigger action as Record Import, Record Create and Record Update. So, that whenever any change will occur in the repository; that workflow will trigger.
    Now create an assignment expression for replacing NULLs with any specific value and use that assignment expression in your workflow by using Assign Step in workflow.
    For exiting records, you will have to replace NULLs manually using the process given by Preethi else you can export those records in an Excel spreadsheet which have NULLs and then replace all NULLs with any string value and then reimport those records in your MDM repository.
    Hope this will solve your problem.
    Regards,
    Varun
    Edited by: Varun Agarwal on Dec 2, 2008 3:12 PM

  • How to delete string or line from unix file(dataset) of application server

    Hi  All,
    After transfer workarea information or all records into dataset(unix file). When I see the file in application server automatically the last line is shown a blank line. I am not passing any blank line.
    I have tried for single record than also the file generates the last line(2nd line) also a blank line.
    When I m reading the dataset, it is not reading the last blank line but why it is showing the last blank line?
    How to delete string or line from unix file(dataset) of application server?
    Please give your comments to resolve this.
    Thanks
    Tirumula Rao Chinni

    Hi Rio,
    I faced similar kind of issue working with files on UNIX platform.
    The line is a line feed to remove it use
    DATA : lv_carr_linefd TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf. 
      DATA : lv_carr_return TYPE char1,                                   
             lv_line_feed   TYPE char1.                                          
      lv_line_feed   = lv_carr_linefd(1).
      lv_carr_return = lv_carr_linefd+1(1).
    Note: IMP: The character in ' ' is not space but is a special
    character set by pressing ALT and +255 simultaneosly
      REPLACE ALL OCCURRENCES OF lv_line_feed IN l_string WITH ' '.
      REPLACE ALL OCCURRENCES OF lv_carr_return IN l_string WITH ' '.

Maybe you are looking for

  • How can I create a new entry without using LOV for foreign keys.

    Referring to TUHRA sample application based on HR database schema. JDeveloper 10.1.3.0.4 How can I create a new employee without using LOV for the foreign key "job_id". On the first page I would like to choose the job_title from adf read-only table.

  • Problem with running a query

    I'm having problem running a query when I use my own userid. The query runs fine when I log on as the owner of the tables. but when I use my own userid ( I have all the privileges to all the tables, snapshots, views needed by the query ) then the que

  • Scripting play all end jump problems.

    hi all in my project i have a script that plays all of my tracks following the 'scripting a dynamic play all button in dvd studio 3' help sheet i found on this discussion forum. for it to work i need to set the end jump of the tracks to a 'play next

  • Load swf and get a SimpleButton in it

    I load a swf and want to get a button in the swf. But the button I get is NULL. I am sure the button's name is right and exists. Could somebody help me to solve this problem? package import flash.display.MovieClip; import flash.net.URLRequest; import

  • Fields embedded within fields

    I have a table 'Letstd1' with two columns 'Letno' and 'Letmem' letno is the letter number and letmem is a 4000 VARCHAR2 field containing the body of a letter. From a form I call a report which must select a letter based on the parameter 'letno' and a