Replace multiple spaces

Hi dear experts,
I need a function/procedure that replaces multiple spaces by one space.
(This is because of an Application Express representation of strings in a report).
(I have to replace ' ' by '_' in this post just because of the same phenomenon).
Strings like "This___is_an_________example"
should become " This_is_an__example".
I need something like:
create or replace function remove_multispaces(text_in in varchar2) return varchar2 is
begin
while instr(text_in,'__') >0 /* two blanks */
loop
execute immediate replace (text_in,'__','_'); /*replace 2 blanks by 1 */
end loop;
return (text_in);
end remove_multispaces;
But this is definitely not working.
Thank you for your help,
Hergen.

SQL> ed
Wrote file afiedt.buf
1 create or replace function replace_multispaces(in_str varchar2) return varchar2 is
2 out_str varchar2(100):=in_str;
3 begin
4 while(instr(out_str,'__')>0) loop
5 out_str:=replace(out_str,'__','_');
6 end loop;
7 return(out_str);
8 exception
9 when others then
10 dbms_output.put_line(sqlerrm);
11* end;
SQL> /
Function created.
SQL> select replace_multispaces('This___is_an_________example') from dual
2 ;
REPLACE_MULTISPACES('THIS___IS_AN_________EXAMPLE')
This_is_an_example
SQL>

Similar Messages

  • Replace multiple space characters with a single space

    Hi,
    Oracle 11g R2.
    Looking for a way to replace multiple space characters in a row with a single space. For example, the text "abc abc" should look like "abc abc". I tried toying with replace, but it only works for the case of 2 spaces. Need a solution for the cases where there could be 2 or more spaces.
    select replace(column1, chr(32)||chr(32), chr(32)) from tablea

    Hi,
    If you had to do this without regular expressions, you could use:
    SELECT  REPLACE ( REPLACE ( REPLACE (str, ' ', '~ ')
                     , ' ~'
              , '~ '
              )     AS new_str
    FROM    table_x;assuming there is some sub-string (I used '~' above) that never occurs right next to a space.
    However, unless you're uisng Oracle 9 (or earlier, which you're not doing) you don't have to do this without regular expressions. As you can see, the way Solomon showed is much simpler.

  • Replacing multiple spaces with another character

    i need to replace multiple spaces with another char in a string
    my code is
    Dim text as String="a bit much             a little much" Dim arr As String() = text.Split({" "c}, StringSplitOptions.RemoveEmptyEntries)Dim newtext As String = String.Join(" ", arr)            MsgBox(newtext)           
     it returns to "a bit much  a little much "
    But i want to replace only long spaces with "="  as  "a bit much =a little much"
    How can i do that?

    This version uses two spaces to split the string and then trims any additional single spaces. It returns "a bit much = a little much".
    Dim text As String = "a bit much a little much "
    Dim parts() As String = text.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
    Dim newText As String
    If parts.Length = 2 Then
    newText = parts(0).Trim & " = " & parts(1).Trim
    End If

  • Replacing multiple spaces with a single space

    Hi friends,
    I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
    Here are the cases:
    1. ' a b c d efg h' should be changed to 'a b c d e f g h'
    2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
    3. 'a b c d e f g h' should not be changed
    4. 'abcdefgh' should not be changed
    Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
    Thanks in advance!

    Hi,
    964559 wrote:
    Hi friends,
    I have a string. It can have zero/one/multiple spaces. I want to make the multiple spaces to single space.
    Here are the cases:
    1. ' a b c d efg h' should be changed to 'a b c d e f g h'One solution is to post your string on this site, and then copy it back again. (See below for a more serious solution .)
    This site is doing exactly what you want the function to do: it replaces multiple consecutive spaces with a single space. As a result, it's hard to see what you mean.
    To preserve spacing on this site, type these 6 characters
    \(small letters only, inside curly brackets) before and after each section where you want spacing preserved.
    2. ' a b c d e f g h ' should be changed to 'a b c d e f g h'
    3. 'a b c d e f g h' should not be changed
    4. 'abcdefgh' should not be changed
    Both REPLACE and TRANSLATE do not help. I don't want to go for LOOP logic. Please help me to get it in SQL query.
    Thanks in advance!Regular expressions make this easy:SELECT TRIM ( REGEXP_REPLACE ( str
    , ' +'
    ) AS compressed_str
    FROM table_x;
    You can use nested REPLACE calls to get the same results, but it's messy.
    Edited by: Frank Kulash on Feb 5, 2013 10:18 AM
    Added TRIM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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.

  • Getting rid of Multiple Spaces in Code View (after Copying/Pasting)

    Hello,
    I'm trying to find a way to get rid of multiple spaces between words in Dreamweaver CS3's code view.
    Oftentimes, when I copy/paste text from elsewhere (e-mail, website, etc), the Dreamweaver code shows up with multiple spaces. Normally, that wouldn't be problem -- except that my blog's auto-tag plug-in doesn't detect selected phrases when there are multiple spaces between words, e.g., it'll detect "Swiss Alps" in a post but not "Swiss  Alps" (notice the extra space between words in the second phrase).
    If at all possible, I'd like to be able to keep Dreamweaver's text formatting option when I copy and paste, as that means I don't need to manually put words in bold/italics.So, is there a way to keep that option while getting rid of all the extra spacing between words?
    By the way, I'm familiar with Wordpress CSS, but not with Dreamweaver CSS. Not sure if there's any difference.
    Any assistance would be much appreciated.

    I make it a point to never paste formatted text into HTML pages.  Formatted text from MS Office usually contains a variety of junk you don't want and I don't have that much faith in MS Word code removal tools.
    Bold and Italics from Word or Outlook should be changed to current HTML tags of <strong> for bold and <em> or emphasis for italics anyway.  Also see Logical Tags here:
    http://www.htmlcodetutorial.com/logical.html
    Find and replace is good for removing whitespace if you know how to do it correctly. Make backup copies just in case things go wrong.  http://www.tjkdesign.com/articles/whitespace.asp
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb

  • Accommodation of multiple space characters without using nbsp - request

    I have dot matrix printer and i want to generate a report using character position and line position.
    For example a line can accommodate 80 chacters and in a page generally accoomdates 72 lines.
    I need to display column value padded with space characters and concatenate with other column and can generate 80 character data set.
    For example name column has varchar2(50) and date_of_birth as date and pay number(10,2)
    I just concatenated as rpad(name,50,' ')||to_char(date_of_birth,'dd-mm-yyyy')||lpad(pay,20,' ') so that all the 80 characters are filled with some characters.
    'dr.s.raghu 01-01-2001 123.45' In between quotes 80 characters are placed including space characters. But while using report and print multiple spaces are getting shrinked as single space character and displays as 'dr.s.raghu 01-01-2001 123.45' If i use nbsp as padded characters, the lettes are getting displayed as nbsp but while on page printing it displayed as space characters.
    I want to accommodate multiple characters of space characters in screen display and as well as in printer image. How to achieve it?
    yours
    dr.s.raghunathan

    dear Piotr
    have seen the example you have shown. I am confident that can be achieved by defining column width and height and example used only three columns. Whereas now i edited my requirement with code tags. Within the column value itself i need multiple spaces between word. Why even in this forum message box unless i use code tag, i am unable to display multiple space characters between any two words. Infact, i am very happy someone also has having the sampe problem and definitely solution will be achieved through some gurus.
    yours
    dr.s.raghunathan

  • How can I set up multiple spaces (desktops) on my new MacBook Pro 10.9.5?  I have six set up on my other computer MacBook Pro 10.8.5 but can't find how to do it on this new one.  Would appreciate help on this.  Cheers.

    How can I set up multiple spaces (desktops) on my new MacBook Pro 10.9.5?  I have six set up on my other computer MacBook Pro 10.8.5 but can't find how to do it on this new one.  Would appreciate help on this.  Cheers.

    It's not completely obvious. What you have to do in Spaces is to position your cursor to the upper right of the screen, after which faint + (plus) sign appears in that area. Click that, upon which another Desktop will appear.
    The + may be difficult or impossible to see with some desktop backgrounds (black, for instance):

  • I am using OSX 10.9.5 and Outlook Web App for emails. When I download an attachment it replaces the space in the file name with   - how can I change this?

    I am using OSX 10.9.5 and Outlook Web App for emails. When I download an attachment it replaces the space in the file name with %20  - how can I change this?

    Click on the below link :
    https://get.adobe.com/flashplayer/otherversions/
    Step 1: select Mac OS  X 10.6-`0.`0
    Step 2 : Safari and FIrefox
    Then click on " Download Now"  button.

  • How to find and replace multiple cells at a time

    I am doing repetitive work re find text in numbers but then replace following cells with text. How can I find and replace multiple cells at a time?
    i.e. doing my own budget spreadsheet and coding all transactions with description and code

    Did you try the "Find/Replace" dialog box?:
    Then click the "Replace All" button in the bottom left.

  • Showing a window in multiple Spaces

    When I use the equivalent of Spaces in Ubuntu, I can pin a window to the screen so that it appears in multiple Spaces. Can I do this in OS X?

    in spaces preference you can assign an application to "every space". this will make every window of this application appear in every space. you can not do it with just one window though.

  • Spaces confusing safari windows (on multiple spaces using command-tab)

    Wondering if this is happening to anyone else.
    I love spaces but something is messed when using safari windows on multiple spaces. Say I have two safari windows open on two different spaces, after command-tabbing to another app when I try to command-tab back to safari it doesn't always go to my last safari window. That is to say that sometimes it goes to the other safari window, and sometimes it doesn't. It's super unpredictable.
    Give it a try, open two safari windows on two different spaces and the command tab to another app and then command tab back to safari - and repeat... you'll find that it will just randomly go to the other window, and then back etc.
    Can't think of anything more annoying in spaces... that's got to be a bug.
    Anyways, let me know if it's happening to you.
    Jay.

    same issue. i have multiple safari windows with multiple tabs on multiple spaces. let's say one space is a rails space; so it has some terminals, safaris, firefoxes, all perhaps with 2 or more tabs. command-tab does not necessarily go back to the window of the app i was just in. whether it's safari or firefox or whatever. this is horribly un-intuitive. come on apple. that's like your thing, right?

  • Multiple Spaces between words in Java

    Hi All
    String s1 = "boy";
    String s2 = "girl";
    String s = s1 + "multiple spaces through keyboard spacebar writing this because when this is posted it will not be visible in the browser" + s2;
    system.out.println(s);
    I need to have multiple spaces between s1 and s2 and need to be shown in the browser(IE) in java.
    If it is a html code, I found we can use <pre> tag,  
    Thanks

    JoachimSauer wrote:
    JoachimSauer wrote:
    commonly written as " "Sorry, the forum software ate what I wrote here. Actually it is written as "& nbsp;" (but without the space, that I needed to add to keep the forum software from butchering it again).You can display a "raw" entity by escaping the ampersand: &#38;#38;nbsp; I use &#38;#38; instead of &#38;amp; because &#38;amp; doesn't work inside CODE blocks, and &#38;#38; does.
    Of course, all this only applies until the next site upgrade, when they break half the existing features in the process of adding a bunch of new features that nobody wanted. :P

  • Powershell (Replacing White Spaces with a comma)

    The object property values output tends to be tabular with varying white spaces between each column. I’m looking for a script that will allow me to:
    Output the object property values to a file
    Remove all white spaces encountered (regardless of the number of spaces)
    Replace the spaces with one (1) comma
    Replace isn’t the answer unless I literally define each instance of spaces and I can’t find any discernable documentation on using Regex…
    -- formattting the output doesn't help either...
    Any guidance / help would be appreciated
    Roderick

    Let's say I ran the PowerShell command below:
    Get-ClusterResource  -Cluster ClusterName | Where-Object {$_.Name -like "SQL Server (*"}
    The output would be something along lines of what you see below.
    I typically output the result set to a csv file, strip the header, replace the spaces with a single comma, and bulk import the data into a SQL Server table for reporting.
    Basically, I'd like a "dynamic way" (not replace with the literal space count between double quotes) of getting rid of the spaces between the columns and replace the spaces with a single comma.
    Name                                        State          
    Group             ResourceType                            
    SQL Server (SRV101O)            Online           SRV101o            SQL Server                              
    SQL Server (SRV301O)            Online           SRV301o            SQL Server                              
    SQL Server (SRV201O)            Online           SRV201o            SQL Server                              
    SQL Server (REMSRV101O)      Offline           REMSRV101o     SQL Server                              
    SQL Server (REMSRV301O)      Offline           REMSRV301o     SQL Server                              
    SQL Server (REMSRV201O)      Offline           REMSRV201o     SQL Server                              
    SQL Server (REMSRV401O)      Offline           REMSRV401O     SQL Server                              
    SQL Server (REMSRV501O)      Offline           REMSRV501O     SQL Server                              
    SQL Server (SRV401O)             Online          SRV401O            SQL Server                              
    SQL Server (SRV501O)             Online          SRV501O            SQL Server                              

  • Replace multiple characters to single character

    Hi friends,
    I would like to replace multiple characters in a string to a single character. The character may be a pipe (|) or a tilde (~).
    For example "|||asdf||123|xyz||" should be changed to "asdf|123|xyz".
    I use Oracle 11g2.
    Thanks in advance!

    Without regexp
    with testdata as (
        select '||asdf||||123|xyz|' str from dual union all
        select 'asdf|123|||||||xyz||||' from dual union all
        select '||||||asdf|||123||||||xyz||||||' from dual
    select
    trim (both '|' from
        replace (
            replace (
                replace (str,'|','|'||chr(0))
                ,chr(0)||'|'
            ,chr(0)
    ) str
    from testdata
    STR
    "asdf|123|xyz"
    "asdf|123|xyz"
    "asdf|123|xyz"
    with regexp
    with testdata as (
        select '||asdf||||123|xyz|' str from dual union all
        select 'asdf|123|||||||xyz||||' from dual union all
        select '||||||asdf|||123||||||xyz||||||' from dual
    select
    trim (both '|' from
        regexp_replace (
            str
            ,'\|+'
            ,'|'
    ) str
    from testdata
    STR
    "asdf|123|xyz"
    "asdf|123|xyz"
    "asdf|123|xyz"
    Message was edited by: chris227 regexp added

Maybe you are looking for

  • If statement error on compile

    Trying to set CUST_REF to 'TITANIC' If ACTIVITY = 'Karate', 'Junior Karate', 'Judo' or 'Junior Judo'      IF (:GROUP_CUSTOMER.ACTIVITY = 'Karate')      OR      (:GROUP_CUSTOMER.ACTIVITY = 'Junior Karate')      OR      (:GROUP_CUSTOMER.ACTIVITY = 'Jud

  • Recovery from backup fails... what to do?

    My iPhone 3gs has been getting slower and slower over some time now. Sometimes it could take up to one minuet to lock the phone after pressing the button. Also my photos was unavailable from the iPhone, every time I tried to access the photos or an a

  • Help needed with Illustrator texture swatches imported into Flash

    Hey, so I  basically scanned a texture into illustrator and added it into the swatches. After drawing a character in illustrator I used the colour of the swatch I had added to colour in my character and by using the tilde button I could move the text

  • Firmware 1.1.2 doesn't work?

    I've updated my iphone to 1.1.2 today... but when I restarted it...It showed that I needed activation.. and Itunes said that activation was unavailable now... Damt... I will go to NYC tommorow...and I need...A CELLPHONE!

  • My Creative Cloud desktop app will not load

    my creative cloud app on my desktop will not load...????