How do I replace multiple consecutive spaces with a single space?

I need to convert any occurrence of multiple consecutive spaces in a string to a single space. How do I create the regex pattern to do that?

r9973 wrote:
Sorry, more like: String test = "Some        Text       Here"Want to convert to String test = "Some Text Here"
Post the code that you used to test the regex. I just tried it and it worked fine for me. All you need to do is apply the regex replaceall to your string variable that holds the string
String test = "Some        Text       Here";
test = test.replaceAll(" +", " ");
System.out.println(test);And thats it.

Similar Messages

  • 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 can I open multiple email messages with a single click?

    On the Mac mini I use at work, I can select several email messages at a time and open them all up by double-clicking the mouse pointer on any of the selected messages. My MacBook Pro at home seems to lack that functionality, even though both are running the same version of Yosemite. In order to open up multiple messages (each, in its own window) on my MacBook Pro, I need to double-click on each individual message, even though I have multiple messages selected on my MacBook Pro, using Yosemite's Mail app. I assume there is an optional setting that can enable multiple messages to be opened by double-clicking on a single selected message, but I have looked through the Mail app's preferences and I come up empty handed. Can someone please clue me in on how to get this functionality on my MacBook Pro?

    Hi,
    There is another similar icon named Bookmarks in the '''Customize''' window which provides the said functionality. You have to add that.

  • Multiple vendor payments with a single u201CYOURSELFu201D cheque

    Hi,
    How do we handle multiple vendor payments with a single u201CYOURSELFu201D cheque, drawn in favor of the paying banker? OR NEFT transfers in SAP.
    Thanks,
    M. Senthil

    Hi
    First things first:
    1. You want to create a single payment document for multiple vendors.  In such a case, you will not be able to use F110. You need to use F-53 or F-f8 in such a case. In the all the vendor masters, maintain the alternative payee with Description as "YOURSELF". There after, if you are using F-53, use FBZ5 to print the cheque in the name of alternative payee.
    2. if you are using F110, multiple payment documents will be created for different vendors. In FBZP Config, you can assign the Payment Advise Form in the Payment Method Step in FBZP Config
    Regards
    Sanil

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

  • How can I create multiple sales orders with reference to one contract?

    Hello Gurus,
    Can you please how can I create multiple sales orders with reference to one contract?
    thanks!
    Rakesh

    hi
    Lets consider example
    In your contract for line item 1 you have entered qty 100
    You careated sales order with 70 quantity, and now you want to creat another sales order for 30
    For this first you need to check what is your item category in contract (VA42)
    Goto VOV7
    SPRO - IMG  - Sales and distribution - Sales - Sales document item - Define item categories - Go to change mode
    Make the completion rule = B Item is completed after full quantity has been referenced

  • How do I merge multiple Excel files with more than one tab in each file using PowerQuery?

    Hello
    I have 12 Excel (.xlsx) files and each file has three identically named and ordered tabs in them. 
    I know how to merge multiple Excel files in a folder using M (those guides are all over the web) but how do I merge multiple Excel files with multiple (yet identically named and ordered) tabs? Surely it is possible? I just don't know how to do it in M.
    Cheers
    James

    What Laurence says is correct, and probably the best thing to do when the sheets have differing structures. Here is an alternate approach that works well when the sheets all have the same structure.
    When you first open the Excel file from Power Query, you can see its structure in the navigator at the right-hand-side of the screen. If you select the root (which is the filename itself) and click Edit, you'll see all the tabs in the sheet as a single table.
    You can now do filtering based on the Name, Item and Kind values. When you've reduced the set of things down to the sheets you want, select the Data column and say "Remove Other Columns". If the sheets don't have any header rows, you can just click the expand
    icon in the header and you'll be done.
    Otherwise, if the sheets have headers or if some other kind of sheet-level transformation is required against each sheet before doing a merge, you'll have to write some M code manually. In the following example, each sheet has a header row consisting of
    two columns: Foo and Bar. So the only step I need to perform before merging is to promote the first row into a header. This is done via the Table.TransformColumns operation.
    let
        Source = Excel.Workbook(File.Contents("C:\Users\CurtH\Desktop\Test1.xlsx")),
        RemovedOtherColumns = Table.SelectColumns(Source,{"Data"}),
        PromotedHeaders = Table.TransformColumns(RemovedOtherColumns,{{"Data", each Table.PromoteHeaders(_)}}),
        ExpandData = Table.ExpandTableColumn(PromotedHeaders, "Data", {"Foo", "Bar"}, {"Data.Foo", "Data.Bar"})
    in
        ExpandData

  • 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

  • How do I replace low res media with the hi res version of the same media?

    How do I replace low res media with the hi res version of the same media without doing all my work all over again?
    Message was edited by: Lemmontage

    Assuming you used Smart Objects, just replace contents with the highres file.

  • How do I number pages consecutively starting with a number other than 1?

    In Pages, how do I number pages consecutively starting with a number other than 1?

    Inspector > Document > Section > Page Numbering:     click on the dropdown menu

  • How do you replace a time capsule with a newer one

    How do you replace a time capsule with a newer one?

    LOL.. pull the old one out.. put the new one in. Setup the new one.. do not copy setting from the old one.. it is better to start over and never copy configuration files.. although you might get away with it.
    Plug the old TC into the new one.. change it to bridge mode.
    You can then access and copy old backups to the new TC if you want. Although IMHO just keep the old TC for 6months. .then wipe it and sell it or use in different role. Do start clean fresh backups on the new TC.
    If that is all useless. ask the specific question and we can try for a specific answer.

  • My old MobileMe account surfaced when I was on a support call. I didn't discover it until the case was closed. How can I replace this obsolete account with my current iCloud account?

    My old MobileMe account surfaced when I was on a support call. I didn't discover it until the case was closed. How can I replace this obsolete account with my current iCloud account?

    Do you mean that you were using the Apple ID which is your ex-MobileMe address? It's still an Apple ID, even though MobileMe itself is dead, and there's nothing to stop you from using it as an ID with Support, or logging in here or in iTunes with it. You should make sure you have a functioning non-Apple email address associated with it.
    Did you migrate your MobileMe account to iCloud before 1 August last? If so, you can set up an iCloud account using it, or if you have already set up a new and separate iCloud account you can still log in with it in System Preferences>Mail, Contacts and Calendars so that it runs alongside your iCloud account.
    If you didn't migrate you can still reactivate the address the same way.
    Anything where you've logged in with the ex-MobileMe address, such as support for something you registered using it or a server such as iTunes, will need to continue using it.

  • Since I am writing the book in Italian,how can I replace the word CHAPTER with CAPITOLO ?

    Since I am writing the book in Italian, how can I replace the word CHAPTER with CAPITOLO ?

    I think you need to run iBA in Italian so the templates are in that language.  You can do that by switching your OS X to Italian and then reopening iBA or perhaps by using this app to just change the iBA language:
    http://www.tj-hd.co.uk/en-gb/languageswitcher/
    see also
    https://discussions.apple.com/message/20745332#20745332

  • How Can I Use Multiple Weblogic Instances in a Single OS

    Hello Everyone,
    Actually I have to install Some different applications. Few of them need weblogic 10.3.6 and others need 10.3.4. The OS am using is Oracle  Enterprise Linux 5.
    Now I am able to install 2 separate(One of 10.3.4 and 10.3.6) instances with two different users,In two different directories.
    I have installed the weblogic 10.3.6 version with a user webadmin and installed node manager with port 5556. This is working fine.
    The main problem here is :
    In the second instance (10.3.4 ) installed with a a different user and gave the port number to NodeManager as 1600 and its not getting started. Its throwing error and also after some errors in the terminal am able to see that its reverting to port number 5556 only.
    What might be the issue?
    I have to install 2 different versions of weblogic in a single Server. But am failing with NodeManager. What Can I do to have multiple weblogic instances with multiple versions in a single server ?
    Can anyone suggest a resolution for this please ?
    Thanks in advance.

    Pl do not spam these forums with multiple posts - How Can I Use Multiple Weblogic Instances in a Single OS

  • How do i combine multiple pdf file into a single pdf file?

    how do i combine multiple pdf files into a single pdf file?

    The thread was started in early March and it's Mid-April, I know this very well. The OP of this thread posted a very common and simple question or maybe he/she would have resolved this. For an Adobe Acrobat user it's not at all difficult to combine multiple PDF files into one. But to combine PDF files full version of Adobe Acrobat is mainly required, otherwise PDF files can't be combined. For example, I'm using Adobe Acrobat 9 Pro. These simple steps are mainly required to combine PDF files:
    Open Adobe Acrobat.
    Click on Combine and click on Merge files into a single PDF.
    A window will be appearing, click on Add Files and select the PDF files you want to combine.
    Arrange the selected files in any order with the help of Move Up and Move Down button.
    Now click on Combine File and the selected PDF files will be combined within a few seconds.
    A new PDF file will be created. Click on Save As and name this new PDF file. Then, click on Save.
    A new PDF file will be created and all the selected PDF files are combined in it. The steps shown above might be different in other versions of Adobe Acrobat. Other than this, some third-party PDF merge software are also available. Most of them are available with a demo version for free evaluation. I've heard much about SysInfoTools PDF Merge software on other forums and directories and it's demo version is freely available. One may check its demo version if Adobe Acrobat (full version) is not available.
    Regards

Maybe you are looking for

  • How to use NT authentication

    I try to use validation of NT authentication every time a user log on to our NT intranet system. That means all of users in our intranet will use same database user name and password to start our forms. Can someone tell me how to get value from NT au

  • Bulk Collect ... FORALL...Insert

    Hello, This works fine but when I want to insert the data in selective columns of TEST2 from TEST1 ,it raise "NOT ENOUGH VALUES" create or replace Procedure Proc_test(p_batch_id IN TEST.BATCH_ID%TYPE) is TYPE l_test IS TABLE OF TEST%ROWTYPE index by

  • XML file transfer over the web

    A company is sending us an XML file via push technology and visual basic: 'Set up to post to client server objHTTP.Open "post", “http://someURL.company.com”, 'Set a standard XML header for the content-type objHTTP.setRequestHeader "Content-Type", "te

  • How to cancel scheduled background job?

    Hi, I have used FM 'HR_START_BATCHJOB_IN_OTHER_SYS' to schedule background job. Some mistake has happend and this FM calling has gone to infinite loop. So, now the system is keep on generating background job. I tried looking into SM36 to stop this ba

  • My iPhone 4 doesn't have Siri installed I have checked in the general and she is not there how do I get her installed?

    I was at a road trip and I was tired and I just got my new iPhone 4s and I held down the home button to ask Siri were was a a hotel but all that came out was voice control. how do I get Siri ?