Replace all ', , ' inside string

i have long string and with pl/sql i want to replace all ', ,' with ', null,'.
I can use replace function like:
prepare_insert := replace(prepare_insert,', ,',', null,');
but it will only replace first ', ,' not all. How can i replace all?

5th database commandment:
Thou shalt not create dynamic insert statements!
I think using bind variables or the using clause in the execute immediate statement would solve the problem.
But of cause you can do it also the hard (and slow) way.
The problem is that your search string is not correct. It does include a leading "," and leaving ",". However if the leavaing "," is also the leading "," of the next replacement part then the function can't take this into account.
Solution 1) Take care of this while building the string in the first place.
While concating the pieces togeather use NVL(value,'null'). If you are sure that there s no value, then write NULL.
Solution 2) Use a double replace
with testdata as (select 'Test, , , , ''ABC''' txt from dual union all
                  select 'Test2, , , ''ABC''' txt from dual
select txt
      ,replace(replace(txt,', ,',',null,'),', ,',',null,')
from testdata;
TXT               REPLACE
Test, , , , 'ABC'     Test,null,null,null, 'ABC'
Test2, , , 'ABC'     Test2,null,null, 'ABC'

Similar Messages

  • 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

  • Replace all special characters in a String with underscore

    I have a String which contains some special characters even(!,$,@,*....).
    I need to replace all the special characters with _ in my String. I do have an idea of using String.replace() and analogous forms, but I would be thankful if anyone can suggest me of a better and an efficient way.
    regards,
    fun_one

    Kaj,
    Thx for your earnest reply. I did have a peep into the API on this method. But the regular expression that I need to use here was beyond my understanding. It did specify some regex that I put to use (something like myString("\D","_"), assuming that I need to replace all non-digit characters ), but it really did not help me getting the result.
    Would you spare some code for me reg. the usage of regular expressions in such a scenario?
    cheers,
    fun_one

  • Replace all occurrences of ENTER in a string

    Hi,
    I have a string which contains line breaks:
    '<HTML><HEAD>
    </HEAD>
    <BODY>'
    and it is shown to me in the debugger as:
    '<HTML><HEAD>#</HEAD>#<BODY>'
    Now I want to replace all line breaks in the string,
    but
    replace all occurrences of `#` in text with ' '.
    doesn't work.
    So if you have an idea how to replace the # symbol for Enter in a string please tell me ;).
    regards,
    Stefan

    Hi,
    Pls use
    replace all occurences of '#' in text with cl_abap_char_utilities=>newline.
    Eddy

  • Replace all in a string

    Hello,
    I need to replace all occurences of
    <image>url to a image goes here</image>
    to
    <img src="url to a image goes here"/>
    where "url to a image goes here" is a url to an image
    Could you let me know how the call to replaceAll method will look like?
    Thank you.

           line = line.replaceAll("<image>([^<]*)</image>", "<img src=\"$1\"/>");

  • Replacing hard-coded strings using Netbeans

    Hi
    Iam using Netbeans 4.0 to replace all the hard-coded string with resourceBundle.getString("...") and prepare the properties file. Thing is it picks all the contents within double quotes and replaces them.
    To avoid replacing all the entire strings, there is an option with name, Non-Internationalization format, using which we can specify the regular expression that can be used for filtering/ignoring the strings that falls under that regular expression.
    For example, if we use "System.out.println" in the regular expression, then the hard-coded strings within println statements are ignored and are not replaced, as one in interested only in translating user-interface strings and not debugging strings. The problem is, the utility searches for the specified word (System.out.println) and ignores the hard-coded string present in that line and replaces the strings in all the remaining lines in the println statement. I need the entire string in the println statement to be ignored and not replaced.
    Can anyone suggest me a solution to ignore the complete string in the println statement.
    Rgds
    Jagan

    Hello Tae,
    In your specific case, i'll go with your Dev Leader since the value returned by the method is not controlled inside the program. If sometime down the line the method returns '1' instead of 'X', if you use the CONSTANT you can change it in the declaration part without bothering about where it is used.
    But you should use meaningful names while defining your CONSTANTS for e.g., instead of C_X use C_TRUE.
    Also bear in mind all organisation data(e.g., Plant, Company Code, Controlling Area etc.) should be defined as CONSTANTS & not hard-coded. In these cases i prefer using the variant tables(TVARVC) to maintain the constants.
    I don't want to start a flame-war here, but imho although use of CONSTANTS increases the maintainability but too much usage of them reduces the readability. With all due respect to those "over diligent" QA reviewers AUTHORITY-OBJECT 'S_TCODE', ASSIGN COMPONENT 'MATNR' et al. are not hard-codes, please don't ask us to declare them as constants
    BR,
    Suhas
    PS: I remember there was an SDN blog on the same topic & it was definitely an interesting read.

  • Using applescript for Find and Replace All in Pages 2.0

    i saw that Pages 2.0 is scriptable
    i try to create a script for merge use to find and replace all occurence of a certain string using a script but Pages doesn't seems to respond to "Find" even using "System Events"
    how can i do to use this function with a script
    Thanx for any help
    S.B.
    ibook G3   Mac OS X (10.4.6)  

    OK, here's another example. This one gets the text as a string and uses the offset property to find "[", presuming it to be a merge delimiter. (Pages' text doesn't support "offset of").
    One failing of this scheme is that the offsets are incorrect if you have inline objects (pictures, shapes, tables, etc.). While it is probably possible to compensate for them, that's a trickier proposition.
    <PRE>-- Example merge replacements:
    property mergeText : {"[name]", "John Smith", "[address]", "1234 Anystreet"}
    on lookup(mergeWord)
    set theCount to count of mergeText
    repeat with x from 1 to theCount by 2
    if item x of mergeText = mergeWord then
    return item (x + 1) of mergeText
    end if
    end repeat
    -- If merge field is not found, delete it (replace it with the empty string)
    return ""
    end lookup
    tell application "Pages"
    repeat
    tell body text of document 1
    -- Get text as a string so that "offset of" can be used.
    set allText to it as string
    set startOffset to offset of "[" in allText
    if (startOffset = 0) then
    exit repeat
    end if
    set endOffset to offset of "]" in allText
    select (text from character startOffset to character endOffset)
    end tell
    set mergeWord to contents of selection
    tell me to lookup(mergeWord)
    set replacement to result
    set selection to replacement
    if (replacement is "") then
    -- Get rid of extra whitespace (space or return)
    -- Do it in a "try" block to handle edge cases at start or end of text.
    try
    set theSel to (get selection)
    set ch1 to character before theSel
    set ch2 to character after theSel
    if ((ch1 is " " or ch1 is return) and (ch2 is " " or ch2 is return)) then
    select character after theSel
    delete selection
    end if
    end try
    end if
    end repeat
    end tell</PRE>
    Titanium PowerBook   Mac OS X (10.4.6)  

  • Search and replace all spaces between quotes with uderscore

    Hello,
    I'm new on Powershell and I'm trying to make the script that:
    searches over file and replaces all the spaces which have been found between quotes;
    removes all quotes (except these which has not value eg "").
    For example:
    Source file:
    string3=string4 string="string1 string2 string23" string8="" string5="string7 string8"
    Destination file:
    string3=string4 string=string1_string2_string23 string8="" string5=string7_string8
    I have been created script that searches the data correctly
    $file="c:\scripts\mk.txt"
    $data=Get-Content $file
    $1
    $regex = [regex]@'
    (?x) # ignore pattern whitespace option
    (?<test>(["'])(?:(?=(\\?))\2.)*?\1)
    $data |% {
    if ($_ -match $regex){
    new-object psobject -property @{
    test = $matches['test']
    }#when adding "|select-object test" I'm getting the correct data
    I have stopped here on search / replace operation (from space to underscore, and by removing the quotes leaving the empty quotes non touched). Can you help me to finish the script?
    Thanks!

    Try this.  It uses the [Regex] Replace static method, with a script block delegate:
    $file="c:\scripts\mk.txt"
    $data=Get-Content $file
    $regex = '(\S+=[^"\s]+)|(\S+="[^"]+")'
    $delegate = { $args[0].value.replace(' ','_') -replace '"(.+)"','$1' }
    $data |% { [regex]::Replace($_,$regex,$delegate) }
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How Can I replace newScale Text Strings with Custom Values?

    How Can I replace newScale Text Strings with Custom Values?
    How can I replace newScale text strings with custom values?
    All  newScale text is customizable. Follow the procedure below to change the  value of any text string that appears in RequestCenter online pages.
    Procedure
    1. Find out the String ID of the text string you would like to overwrite by turning on the String ID display:
    a) Navigate to the RequestCenter.ear/config directory.
    b) Open the newscale.properties file and add the following name-value pair at the end of the file:res.format=2
    c) Save the file.
    d) Repeat steps b and c for the RmiConfig.prop and RequestCenter.prop files.
    e) Stop and restart the RequestCenter service.
    f) Log  in to RequestCenter and browse to the page that has the text you want  to overwrite. In front of the text you will now see the String ID.
    g) Note down the String ID's you want to change.
    2. Navigate to the directory: /RequestCenter.ear/RequestCenter.war/WEB-INF/classes/com/newscale/bfw.
    3. Create the following sub-directory: res/resources
    4. Create the following empty text files in the directory you just created:
    RequestCenter_0.properties
    RequestCenter_1.properties
    RequestCenter_2.properties
    RequestCenter_3.properties
    RequestCenter_4.properties
    RequestCenter_5.properties
    RequestCenter_6.properties
    RequestCenter_7.properties
    5. Add the custom text strings to the appropriate  RequestCenter_<Number>.properties file in the following manner  (name-value pair) StringID=YourCustomTextString
    Example: The StringID for "Available Work" in ServiceManager is 699.
    If you wanted to change "Available Work" to "General Inbox", you  would add the following line to the RequestCenter_0.properties file
         699=General Inbox
    Strings are divided into the following files, based on their numeric ID:
    Strings are divided into the following files, based on their numeric ID:
    String ID  File Name
    0 to 999 -> RequestCenter_0.properties
    1000 to 1999 -> RequestCenter_1.properties
    2000 to 2999 -> RequestCenter_2.properties
    3000 to 3999 -> RequestCenter_3.properties
    4000 to 4999 -> RequestCenter_4.properties
    5000 to 5999 -> RequestCenter_5.properties
    6000 to 6999 -> RequestCenter_6.properties
    7000 to 7999 -> RequestCenter_7.properties
    6. Turn off the String ID display by removing (or commenting out) the line "res.format=2" from the newscale.properties, RequestCenter.prop and RmiConfig.prop files
    7. Restart RequestCenter.
    Your customized text should be displayed.

    I've recently come across this information and it was very helpful in changing some of the inline text.
    However, one place that seemed out of reach with this method was the three main buttons on an "Order" page.  Specifically the "Add & Review Order" button was confusing some of our users.
    Through the use of JavaScript we were able to modify the label of this button.  We placed JS in the footer.html file that changes the value of the butt

  • DUMP: replace all occurrences of space in string1 with string2.

    Why does this statement results in a dump:
    replace all occurrences of space in string1 with string2.
    same with
    replace all occurrences of ' ' in string1 with string2.
    string2 is a string without spaces!
    Is there any drawback on using this statements as a workaround?
    while sy-subrc eq 0.
      replace space with string2 into string1.
    endwhile.
    Thanks
    norbert

    Hi,
    See this example i got from ABAPDOCU
    replacing values
    DATA: t4(10) TYPE c VALUE 'abcdefghij',
          string4 LIKE t4,
          str41(4) TYPE c VALUE 'cdef',
          str42(4) TYPE c VALUE 'klmn',
          str43(2) TYPE c VALUE 'kl',
          str44(6) TYPE c VALUE 'klmnop',
          len4 TYPE i VALUE 2.
    string4 = t4.
    WRITE string4.
    REPLACE str41 WITH str42 INTO string4.
    WRITE / string4.
    string4 = t4.
    REPLACE str41 WITH str42 INTO string4 LENGTH len4.
    WRITE / string4.
    string4 = t4.
    REPLACE str41 WITH str43 INTO string4.
    WRITE / string4.
    string4 = t4.
    REPLACE str41 WITH str44 INTO string4.
    WRITE / string4.
    SKIP.
    ULINE.
    Example for condensing strings
    DATA: string9(25) TYPE c VALUE ' one  two   three    four',
          len9 TYPE i.
    len9 = strlen( string9 ).
    WRITE: string9, '!'.
    WRITE: / 'Length: ', len9.
    CONDENSE string9.
    len9 = strlen( string9 ).
    WRITE: string9, '!'.
    WRITE: / 'Length: ', len9.
    CONDENSE string9 NO-GAPS.
    len9 = strlen( string9 ).
    WRITE: string9, '!'.
    WRITE: / 'Length: ', len9.
    SKIP.
    ULINE.
    Thanks & Regards,
    Judith.

  • Replacing all text in book with sample text

    Hello fellows,
    Is there a way to replace all the textual content in a book with some sample text using Extendscript?
    If yes, could you please point me to the relevant APIs?
    Thank you for your help in advance!

    Yes, the point that Rick was making crossed my mind, too. Using regular expressions, you can easily specify which characters should be replaced. Listing a number of same-width characters and replacing them with an "x" is as easy as this:
    sTextString.replace ( /[abcdefghknopqrsuvyz]/g, "x" );
    This would leave the non-mentioned characters as they are. Depending a little bit on the fonts that are used, of course, as they might have different character widths for more than the ones I left out. But even if you only replace a couple of characters throughout the doc, it would be enough to get the desired effect.
    The difficulty is getting to the text strings and also to replace them. There are many objects for which a GetText method exists, but you have to set the flags such that you actually get the right text strings out of that method. And then you have to figure out where in the doc the text string is, then delete the existing one and add the replacement. All of this has to be done without deleting any markers or anchors.
    Another approach might be to set the text location to the first character in the main flow and then walking through the entire document character by character, testing each one and replacing it where required. But I don't think you would get into tables with that method, as those are linked to the running text via an anchor in that running text. So the table cells will have to be processed separately. And if you do have a method to change text in table cells, you can use that method on all paragraphs.
    I think Rick has more experience in tweaking text strings. I am usually working on structured documents and only handling the element objects and their hierarchy, not so much changing the text content of documents. Rick, do you have an approach to walk through all text strings in a document and replace them without breaking anything ?
    Ciao
    Jang

  • Replace integers inside of an array

    Hi,
    I'm currently trying to replace integers inside of a multidimensional array, but I don't know how to make it so that it doesn't skip them (if they've been changed, I assume). Here's an example, hopefully you understand, if not please let me know and I'll try to go further in depth.
    public class Example {
         private int[][] replaced = new int[][] {
              {0, 1}, {1, 3}, {2, 4}, {3, 5}, {4, 6}, {5, 2}, {6, 0}
         public static void main(String[] var) {
              new Example().replace();
          * Should replace the integer inside of the first index of replaced with the second, without skipping any
         public void replace() {
              for (int a = 0; a < 6; a++) {
                   if (a == replaced[a][0]) {
                        a = replaced[a][1];
                        System.out.println("replaced " + replaced[a][0] + " with " + replaced[a][1]);
    }

    sharkura wrote:
    More specifically, your replace function is doing this ... if the value at a,0 is equal to the current array index a, set the array index a to the value at a,1.
    This does not replace the value at a,0 with the value at a,1. With your specific data, it updates the loop index prematurely, so one or more values are skipped. Without running it, it may cause your loop to execute without termination. With some data, it will definitely do that.
    This will make your loop behave very strangely.  It is almost never correct to modify a loop index variable inside the loop.
    To repeat:
    It is almost never correct to modify a loop index variable inside the loop.
    ¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Replace all

    Hi there,
    i got this codes online for replacing a word in textarea . The problem is it only replace the first word it match, while other same word still remain un-replace.how to modify it so that it can replace all the particular words that i wantto replace in the textarea.
    Document doc;
    doc=text2.getDocument();
    SimpleAttributeSet set= new SimpleAttributeSet();
    String str1 = JOptionPane.showInputDialog(null,"Enter the word to be replace:","replace",JOptionPane.QUESTION_MESSAGE);
    String str2= JOptionPane.showInputDialog(null," Replace the word with :","replace",JOptionPane.QUESTION_MESSAGE);
    int index=0;
    if(str1!="" && str2!="")
    try{          
    index=text2.getText().indexOf(str1);
    doc.remove(index,str1.length());
    doc.insertString(index,str2,set);
    }catch(BadLocationException b){
    JOptionPane.showMessageDialog(null," Word not found !","Not Found",JOptionPane.ERROR_MESSAGE);
    }

    Sorry, hit the post button too soon
    Document doc = text2.getDocument();
    String replaceThis = JOptionPane.showInputDialog(null,"Enter the word to be replace:","replace",JOptionPane.QUESTION_MESSAGE);
    String replaceWith = JOptionPane.showInputDialog(null," Replace the word with :","replace",JOptionPane.QUESTION_MESSAGE);
    SimpleAttributeSet set= new SimpleAttributeSet();
    if(!replaceThis.equals("") && !replaceWith.equals(""))
      if(text2.getText().indexOf(replaceThis) == -1)
         JOptionPane.showMessageDialog(null," Word not found !","Not Found",JOptionPane.ERROR_MESSAGE);
      else
        while(text2.getText().indexOf(replaceThis) != -1)
          try
            int index=text2.getText().indexOf(replaceThis);
            doc.remove(index,replaceThis.length());
            doc.insertString(index,replaceWith,set);
          catch(BadLocationException e)
            // should not happen
            e.printStackTrace();
    }

  • Replace " from the string

    Hi,  I am not able to remove " (double quotes) from a sting.
    I am using replace function in webi but getting error.
    example sting: Yellow stone"discovery"
    i have tried like this: =replace([varible];""";"")  but getting error. can anybody help me in removing the " from sting.
    Thanks.

    Description
    Replaces part of a string with another string
    Function Group
    Character
    Syntax
    string Replace(string input_string; string string_to_replace; string replace_with)
    EX:=Replace ([[variable]]; Char(34) ;"")
    Input
    input_string                     The input string 
    string_to_replace             The string within input_string to be replaced 
    replace_with                    The string to replace string_to_replace with. 
    Output
    The string with the part replaced
    Example
    Replace ("New YORK";"ORK";"ork") returns "New York"
    All the best,
    Praveen

  • Is there a "Replace All" command?

    This seems like a no-brainer....  I found the  "Ctrl+F" find and replace, but it only replaces a sindle instance of a text string.  I also found the complext find dialog.  It lets you find all occurances, but (apparently) you cannot do replaces from there.  Is it possible to do a "Find and Replace All" in my PDF? 
    Many Thanks.
    Win 7, Acr XI.

    The more you think of Acrobat as being like Word, the more frustrating it will get. Text editing is a desperate last resort, not a normal process.

Maybe you are looking for