Replacing many spaces with single space in a string

Hi!
I have the following strings:
"Eric       B"
"John                 A"
"Mary Anne   C"But I want them to be like this:
"Eric B"
"John A"
"Mary Anne C"Do anyone have an idea how to do this?
Edited by: suladna on Aug 2, 2008 5:42 AM

Use this:
String s = "Mary    Anne   C";
System.out.println(s.replaceAll("\\s+", " "));Edited by: prigas on Aug 2, 2008 6:15 AM

Similar Messages

  • Replacing inconsistant spacing with single space in a string

    is it possible to replace multiple spaces within a string with one space only. Number of spaces is different all the time.
    say one field contains strings with imbedded spaces
    I need to replace all these values so that there will be only one space between words.
    For Eg.
    Input                             Expected Result
    aaa    bbb                       aaa bbb
    ww                vv             ww vv
    ww ss      kk                    ww ss kk
    [/code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    user11253970 wrote:
    I am in Oracle 9i :( I can not use reg exp
    Assuming strings do not contain CHR(0) (character with ascii code 0):
    SQL> SELECT  'aaa          bbb  aaa bbb' str,
      2          replace(replace(replace('aaa          bbb  aaa bbb',' ',' ' || CHR(0)),CHR(0) || ' '),CHR(0)) new_str
      3    FROM  dual
      4  /
    STR                                 NEW_STR
    aaa          bbb  aaa bbb           aaa bbb aaa bbb
    SQL> SY.

  • Firefox is replacing double quotes with single quotes.

    In WordPress and at other sites where I input and save text, Firefox is replacing double quotes with single quotes when I save. It's also showing double quotes as single quotes on websites. I tried uninstalling and reinstalling, and it's still happening.

    Do you have the needed font installed?
    *http://en.wikipedia.org/wiki/Punctuation

  • Replacing " (double quote) with ' (single quote)

    Hi there,
    I have the following method to manipulate user input. All I want to do is, to replace the double quote with a single quote. The implementation I tried was,
    this.replace(desc, "\"", "'");
    This does not work for me. It jsut removes the double quote and does not introduces the single quote. Could any one please advise?
    Thanks,
    Des
    public static String replace(String line, String oldString, String newString) {
              if(line != null && oldString != null && newString != null) {
                   int index = 0;
                   while ((index = line.indexOf(oldString, index)) >= 0) {
                        line = line.substring(0, index) +
                             newString +
                             line.substring(index + oldString.length());
                        index += newString.length();
              return line;
         }

    Bad luck.. I am unable to get it still.
    This is the code I am using (implemetation is in a JSP. I am using this code to test it).
    public class Test{
    public static void main(String args[]){
         String s = args[0];
         Test t = new Test();
         String doubleQuote = "\"";
         System.out.println(" output :"+ t.replace(s,doubleQuote,"'"));
         //System.out.println(" output :"+ t.replace(s,"\"","'"));
         //System.out.println(" output :"+ t.replace('"', '\''));
    public static String replace(String line, String oldString, String newString) {
              if(line != null && oldString != null && newString != null) {
                   int index = 0;
                   while ((index = line.indexOf(oldString, index)) >= 0) {
                             System.out.println(" line count :");
                        line = line.substring(0, index) +
                             newString +
                             line.substring(index + oldString.length());
                        index += newString.length();
              return line;
    }mshn02
    The main problem is I am stuck with the server's version of Java (which I have no control on it). I could not use 1.4.2

  • Replacing multiple nodes with single node in OSB

    Hi,
    I have a case where I will get a xml like below:
    <LINEITEMS>
         <LINE_ITEM>
              <LINE_ITEMNO>1</LINE_ITEMNO>
              <STATUS_CODE>0</STATUS_CODE>
              <MESSAGE>MESSAGE1</MESSAGE>
         </LINE_ITEM>
         <LINE_ITEM>
              <LINE_ITEMNO>3</LINE_ITEMNO>
              <STATUS_CODE>0</STATUS_CODE>
              <MESSAGE>MESSAGE3</MESSAGE>
         </LINE_ITEM>
         <LINE_ITEM>
              <LINE_ITEMNO>1</LINE_ITEMNO>
              <STATUS_CODE>0</STATUS_CODE>
              <MESSAGE>MESSAGE2</MESSAGE>
         </LINE_ITEM>
         <LINE_ITEM>
              <LINE_ITEMNO>3</LINE_ITEMNO>
              <STATUS_CODE>0</STATUS_CODE>
              <MESSAGE>MESSAGE4</MESSAGE>
         </LINE_ITEM>
    <LINE_ITEM>
              <LINE_ITEMNO>2</LINE_ITEMNO>
              <STATUS_CODE>1</STATUS_CODE>
              <MESSAGE>MESSAGE5</MESSAGE>
         </LINE_ITEM>
    </LINEITEMS>
    I need to make this as below:
    <LINEITEMS>
         <LINE_ITEM>
              <LINE_ITEMNO>1</LINE_ITEMNO>
              <STATUS_CODE>0</STATUS_CODE>
              <MESSAGE>MESSAGE1;MESSAGE2</MESSAGE>
         </LINE_ITEM>
         <LINE_ITEM>
              <LINE_ITEMNO>3</LINE_ITEMNO>
              <STATUS_CODE>0</STATUS_CODE>
              <MESSAGE>MESSAGE3;MESSAGE4</MESSAGE>
         </LINE_ITEM>
    <LINE_ITEM>
              <LINE_ITEMNO>2</LINE_ITEMNO>
              <STATUS_CODE>1</STATUS_CODE>
              <MESSAGE>MESSAGE5</MESSAGE>
         </LINE_ITEM>
    </LINEITEMS>
    I need to have only one entry for each line Item.
    Please let me know on the approach on how to do it in OSB.
    Thanks

    You can try this :-
    let $out:= <LINEITEMS>{ for $x in 1 to count($input/LINE_ITEM)
                                  let $LineItme := $input/LINE_ITEM[$x]/LINE_ITEMNO
                             let $match:= for $y in $x to count($input/LINE_ITEM)
                                  where $input/LINE_ITEM[$y]/LINE_ITEMNO= $LineItme
                                  return $input/LINE_ITEM[$y]/MESSAGE
                                  return
                                  <LINE_ITEM>
                                       <LINE_ITEMNO>{$LineItme/text()}</LINE_ITEMNO>
                                       <STATUS_CODE>{data($input/LINE_ITEM[$x]/STATUS_CODE)}</STATUS_CODE>
                                       <MESSAGE>{fn:data($match)}</MESSAGE>
                                  </LINE_ITEM>
    }</LINEITEMS>
    return $out
    You many then have to remove duplicates with line items. use fn:distinct() and then loop through.

  • ACS - Replace IP Subnet with Single IP's

    Hi Everyone,
    I have been charged with a task to create individual entries in our ACS for each of our network devices. I am new to the ACS and the documentation does not seem to cover this scenario. Right now we have all our devices fall under a single subnet.
    When I try to create a device within the subnet, it tells me IP subnets overlap with those defined for device.
    If I try to change the existing IP Subnet to an IP range so I can exclude some devices from the IP Subnet, it tells me I cannot switch from IP Mask mode to IP Range mode.
    I am guessing I need to delete the the record for the IP subnet and add each device back individually. My concern is that none of my devices will work until I add each one back.
    Is this correct or is there a better way to go about this?
    Thanks,
    DC

    You can configure the default network device with the same settings ad your subnet, remove the subnet definition and re-add the hosts one by one. You can also use file import to reduce time.
    Sent from Cisco Technical Support Android App

  • Replace characters between with single * in variable

    Hi Experts ,
    I want to replace all characters between <  > with *. Data is stored in variable type char255.
    Example ,
    Suppose variable contains : Wage Type <Wage Type> Not Valid For Interface ID <ID>
    I want output as Wage Type * Not Valid For Interface ID *.
    Thanks & Regards ,
    Jigar Thakkar

    Hi Jigar,
    Find the length of the string and use DO...ENDDO statement. Inside the loop, didnt consider the text between < and > and move to another string and add * when  > is encountered in the string.
    data:
      gv_len type i,
      gv_str type string value 'Wage Type <Wage Type> Not Valid For Interface ID <ID>',
      gv_rep_str type string,
      gv_flag type char1,
      gv_index type sy-index.
    gv_len = strlen( gv_str ).
    do gv_len times.
    gv_index = sy-index - 1.
    if gv_str+gv_index(1) = '<'.
    gv_flag = 'X'.
    continue.
    elseif gv_str+gv_index(1) = '>'.
    clear gv_flag.
    concatenate gv_rep_str '*' into gv_rep_str.
    continue.
    elseif gv_flag is initial.
    concatenate gv_rep_str gv_str+gv_index(1) into gv_rep_str.
    endif.
    enddo.
    write:/ gv_rep_str.
    Thanks,
    Vinay
    Edited by: Vinaykumar G on May 29, 2009 8:04 PM

  • 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

  • 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                              

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

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

  • Replacing Home Space with a specific Group Space.

    Hi,
    We have a Webcenter Spaces 11.8 environment.
    We are trying to completely bypass the home space and take the user to a specific space.
    While this is possible to do it through the initial redirection based on application/enterprise role, some re-directions are causing the user to land in the home space.
    Also, the user can get to the home space pages by typing in the url. We want to restrict the user from viewing the home space altogether and replace it completely with our group space.
    Approach1 : Page Links -
    We tried to bring in pages from the group space into the home space navigation model as page links. Even if the group space is public, we cannot link to its pages as we cannot see the pages in the page link popup. Only home space pages are shown. Is this expected? How do we bring in pages from a specific group space into the home page navigation?
    Approach 2: Group Space Pages Query -
    We can bring all the pages from the "Default Navigation Model" of the group space into the home space navigation model. However, the landing page upon login needs to be a visible page in the home space. How do we get the user redirected to a specific page in a group space and make that node as selected once the user logs in.
    Thanks in advance.

    Hi,
    Check this code.
    data : role(10) type c value 'crick ter',
           role1(10) type c,
           role2(10) type c.
    write: / role.
    SPLIT role AT space INTO role1 role2.
    concatenate role1 role2 into role separated by '_'.
    write: / role.
    <REMOVED BY MODERATOR>
    Regards.
    Edited by: Alvaro Tejada Galindo on Mar 10, 2008 7:25 PM

  • How to replace blank spaces with zero's in the report

    hai sdn guys,
                         we have a requirement where we cannot have any blank fields in the report and i need to replace the blanks with a zero. What is the best way to do it.

    Hi Sunitha,
    It is not proper that you are posting the same question multiple times:
    Re: report o/p should not have blank spaces in - in case of no value
    should get 0's in place of blank value in  the output of the report
    That too inspite of my requesting you not to do so.
    I am not sure if you have ever gone through the Rules Of Engagement which are prominently posted in each forum, but I think it is SDN courtesy to provide proper feedback when posting a question and assign points as deemed fit. This helps (and motivates) everyone to work on your problem and try to give you a solution. I hope you will be more careful in the future. Thanks!

Maybe you are looking for

  • Any ideas on getting facebook 'like' links working in SMS and MMS?  A few issues Apple might fix please?

    Hi, I work in a Mobile Marketing company where clients use our bulk SMS / MMS messaging service in Australia.  A few things I've noticed where iPhones are falling short in comparison to the competition in RECEIVING messages (and I hope are fixed beca

  • How to add the percent (%) symbol at the end of a number in a form field

    Hi, I need to display a percentage as a result of a calculation in the form: 80.23% How can I direct the Format Mask     inside an APEX form to display that? I use a PL/SQL expression Thank you

  • E-Mailing a PDF Form and not an .xml file

    I have created a PDF form for staff to request time off.  The form is to be emailed to the Manager for approval.  I used the "Submit by E-Mail" button, however, when I hit the Submit by E-Mail button, it submits an .xml file.  I have looked through t

  • MySQL database with SQL Toolkit

    Hi, we are using CVI 2012 and the SQL Toolkit 2.2 and we want to connect to a MySQL database. The MySQL database was created with MySQLServer. When we try to connect with DBConnect we get an error. How can we connect the MySQL Database? What do we ha

  • Two Domains

    I have a windows 2003 AD domain.  I need to change the domain name and also upgrade from 2003.  I am in the process of setting up a Windows 2008 AD Domain.  I will setup full trust between the two domains and slowly move resources. Can I setup the ne