Trying to remove whitespace from a string

Lets say I have the string "A man a plan a canal Panama"
How would I turn that into AmanaplanacanalPanama" ?
I've read a little about 'string buffer' but the teacher hasn't taught us how to use that yet (hasn't taught us much of anything). Is there any way to do this withough using a string buffer?
I'm making a palindrom tester, and I'm almost finished, but I can't seem to deal with these white spaces. Please help.

I'd do it using String's replaceAll method, to replace all occurences of space, or of one or more spaces, with the empty string "", but I don't know if you're supposed to use that or roll your own with brute force.
The brute force way would be to do something like this: Allocate a char array as big as the sentence.
for each char in the sentence (using String.charAt) {
    if it is not a space {
        add it to the array
        increment the number of non-space characters counter
Use whatever char array methods String has to build a new String from the
first N chars of the array, where N is the number of non-space chars.

Similar Messages

  • I am trying to remove something from the background of my image how is this done.

    i am trying to remove something from the background of my image how is this done.

    jboll0820 wrote:
    how is this done.
    Generally, using a different program than Lightroom, e.g. Photoshop.
    Note: you can remove objects in Lightroom by stringing dust-spot removal bubbles across them, but that may or may not be preferrable. If you do go that route, it may be essential to position strategically *after* initial placement.

  • Firefox will not open at all. I tried to remove it from the programs to try to reinstall it but it wont let me remove it. So I tried to download again anyways and ff still wont open. My email is alicia@*****

    Firefox will not open at all. I tried to remove it from the programs to try to reinstall it but it wont let me remove it. So I tried to download again anyways and ff still wont open. My email is alicia@****

    Did you check your security software (firewall)?
    A possible cause is security software (firewall) that blocks or restricts Firefox without informing you about that, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process.
    See [[Server not found]] and [[Firewalls]] and http://kb.mozillazine.org/Firewalls
    If necessary then also see:
    * http://kb.mozillazine.org/Browser_will_not_start_up
    * http://kb.mozillazine.org/Error_loading_websites

  • I tried to remove Trovi from macbook pro but it doesnt go away

    I tried to remove Trovi from macbook pro but it does not go away. Trovi opens right away

    How to remove Trovi adware from Mac - MacSecurity
    Helpful Links Regarding Malware Problems
    If you are having an immediate problem with ads popping up see The Safe Mac » Adware Removal Guide and AdwareMedic.
    Open Safari, select Preferences from the Safari menu. Click on Extensions icon in the toolbar. Disable all Extensions. If this stops your problem, then re-enable them one by one until the problem returns. Now remove that extension as it is causing the problem.
    The following comes from user stevejobsfan0123. I have made minor changes to adapt to this presentation.
    Fix Some Browser Pop-ups That Take Over Safari.
    Common pop-ups include a message saying the government has seized your computer and you must pay to have it released (often called "Moneypak"), or a phony message saying that your computer has been infected, and you need to call a tech support number (sometimes claiming to be Apple) to get it resolved. First, understand that these pop-ups are not caused by a virus and your computer has not been affected. This "hijack" is limited to your web browser. Also understand that these messages are scams, so do not pay any money, call the listed number, or provide any personal information. This article will outline the solution to dismiss the pop-up.
    Quit Safari
    Usually, these pop-ups will not go away by either clicking "OK" or "Cancel." Furthermore, several menus in the menu bar may become disabled and show in gray, including the option to quit Safari. You will likely have to force quit Safari. To do this, press Command + option + esc, select Safari, and press Force Quit.
    Relaunch Safari
    If you relaunch Safari, the page will reopen. To prevent this from happening, hold down the 'Shift' key while opening Safari. This will prevent windows from the last time Safari was running from reopening.
    This will not work in all cases. The shift key must be held at the right time, and in some cases, even if done correctly, the window reappears. In these circumstances, after force quitting Safari, turn off Wi-Fi or disconnect Ethernet, depending on how you connect to the Internet. Then relaunch Safari normally. It will try to reload the malicious webpage, but without a connection, it won't be able to. Navigate away from that page by entering a different URL, i.e. www.apple.com, and trying to load it. Now you can reconnect to the Internet, and the page you entered will appear rather than the malicious one.
    An excellent link to read is Tom Reed's Mac Malware Guide.
    Also, visit The XLab FAQs and read Detecting and avoiding malware and spyware.
    See these Apple articles:
      Mac OS X Snow Leopard and malware detection
      OS X Lion- Protect your Mac from malware
      OS X Mountain Lion- Protect your Mac from malware
      OS X Mavericks- Protect your Mac from malware
      About file quarantine in OS X
    If you require anti-virus protection Thomas Reed recommends using ClamXAV. (Thank you to Thomas Reed for this recommendation.)
    From user Joe Bailey comes this equally useful advice:
    The facts are:
    1. There is no anti-malware software that can detect 100% of the malware out there.
    2. There is no anti-malware that can detect everything targeting the Mac.
    3. The very best way to prevent the most attacks is for you as the user to be aware that
         the most successful malware attacks rely on very sophisticated social engineering
         techniques preying on human avarice, ****, and fear.
    4. Internet popups saying the FBI, NSA, Microsoft, your ISP has detected malware on
        your computer is intended to entice you to install their malware thinking it is a
        protection against malware.
    5. Some of the anti-malware products on the market are worse than the malware
        from which they purport to protect you.
    6. Be cautious where you go on the internet.
    7. Only download anything from sites you know are safe.
    8. Avoid links you receive in email, always be suspicious even if you get something
        you think is from a friend, but you were not expecting.
    9. If there is any question in your mind, then assume it is malware.

  • I'm trying to remove pages from my menu by exluded them via the page properties.  When I do that Muse crashes with the following error, "menuItemBox U32584 has no associates page!"  Any help is appreciated.

    I'm trying to remove pages from my menu by excluding them via the page properties.  When I do that Muse crashes and displays the following error, "Adobe Muse CC has encountered an error and wil not exit...." "menuItemBox U32584 has no associates page!"
    Any help is appreciated.
    Thanks,
    Carole

    One or more menu widgets within your site have become out-of-sync with the structure of your site in Plan view. If you send us the file we can repair and return it. Or you could delete and recreate the menu widgets.
    Please send us the .muse file at [email protected] along with a link to this thread. If the file is larger than 20Mb you can use a service like Adobe SendNow, Dropbox, WeTransfer, etc. (If you use a service, please include your return e-mail address in the body of the message, since not all services include it in the sharing invite they send.)
    Thanks.

  • Remove $%&* characters from a String

    Hi,
    I have the following program that is supposed to detect a subsequence from a String (that contains $ signs) and remove it. This is a bit tricky, since because of $ signs, the replaceAll method for String does not work. When I use replaceAll for removing the part of the String w/ no $ signs, replaceAll works perfectly, but my code needs to cover the $ signs as well.
    So far, except for replaceAll, I have tried the following, with the intent to first remove $ signs from only that specific sequence in the String (in this case from $d $e $f) and then remove the remaining, which is d e f.
    If anyone has any idea on this, I would greatly appreciate it!
    Looking forward to your help!
    public class StringDivider {
         public static void main(String [] args)
              String symbols = "$a $b $c $d $e $f $g $h $i $j $k l m n o p";
             String removeSymbols = "$d $e $f";
             int startIndex = symbols.indexOf(removeSymbols);
             int endIndex = startIndex + removeSymbols.length()-1;
             for(int i=startIndex;i<endIndex+1;i++)
                  if(symbols.charAt(i)=='$')
                       //not sure what to do here, I tried using replace(oldChar, newChar), but I couldn't achieve my point, which is to
                       //delete $ signs from the specific sequence only (as opposed to all the $ signs)
             System.out.println(symbols);
    }

    A little modification on the last version:
    This one's more accurate.
    public class StringDivider {
         public static void main(String [] args){
              String symbols = "$a $b $c $d $e $f $g $h $i $j $k l m n o p";
                  String removeSymbols = "$d $e $f $g";
                  if(symbols.indexOf(removeSymbols)!=-1)
                       if(removeSymbols.indexOf("$")!=-1)
                            removeSymbols = removeSymbols.replace('$', ' ').trim();
                            removeSymbols = removeSymbols.replaceAll("[ ]+", " ");
                            String [] symbolsWithoutSpecialChars = removeSymbols.split(" ");
                            for(int i=0;i<symbolsWithoutSpecialChars.length;i++)
                                 symbols = symbols.replaceAll("[\\$]*"+symbolsWithoutSpecialChars, "");
                             symbols = symbols.replaceAll("[ ]+", " ");
                   else
                        symbols = symbols.replaceAll(removeSymbols, "");
              symbols = symbols.trim();
              System.out.println(symbols);

  • Removing characters from a String

    Hi!
    I have a large String that has some unwanted characters in it that I want to remove. Here is an example:
    AA1lbmNvZGVkUGFy\015\012YW1zdAACW0JbABBlbm5MQ2Is there any method I can use to remove the characters \015\012 from the String. I looked at the method String.replace(char, char); but this is unsuitable because I can only remove one charater at a time an I may have this character occuring legitimately elsewhere in my String. Would it be possible in some way to traverse the String and identify the pattern of \015\012 and remove that.
    I'd appreciate any help,
    Thanks
    Chris

    Specifically,  str = str.replaceAll("\\\\01[25]", "");The replaceAll method is only available in v1.4.0 or later.

  • Removing characters from a String (concats, substrings, etc)

    This has got me pretty stumped.
    I'm creating a class which takes in a string and then returns the string without vowels and without even numbers. Vowels and even characters are considered "invalid." As an example:
    Input: "hello 123"
    Output: "hll 13"
    The output is the "valid" form of the string.
    Within my class, I have various methods set up, one of which determines if a particular character is "valid" or not, and it is working fine. My problem is that I can't figure out how to essentially "erase" the invalid characters from the string. I have been trying to work with substrings and the concat method, but I can't seem to get it to do what I want. I either get an OutOfBoundsException throw, or I get a cut-up string that just isn't quite right. One time I got the method to work with "hello" (it returned "hll") but when I modified the string the method stopped working again.
    Here's what I have at the moment. It doesn't work properly for all strings, but it should give you an idea of where i'm going with it.
    public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         }So does anybody have any advice for me or know how I can get this to work?
    Thanks a lot.

    Thansk for the suggestions so far, but i'm not sure how to implement some of them into my program. I probably wasn't specific enough about what all I have.
    I have two classes. One is NoVowelNoEven which contains the code for handling the string. The other is simply a test class, which has my main() method, used for running the program.
    Here's my class and what's involved:
    public class NoVowelNoEven {
    //data fields
         private String str;
    //constructors
         NoVowelNoEven(){
              str="hello";
         NoVowelNoEven(String string){
              str=string;
    //methods
         public String getOriginal(){
              return str;
         public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         public static int countValidChar(String string){
              int valid=string.length();
              for(int i=0; i<=string.length()-1; i++){
                   if(isNumber(string.charAt(i))==false){
                        if((upperVowel(string.charAt(i))==true)||lowerVowel(string.charAt(i))){
                             valid--;}
                   else if(even(string.charAt(i))==true)
                        valid--;
              return valid;
         private static boolean even(char num){
              boolean even=false;
              int test=(int)num-48;
              if(test%2==0)
                   even=true;
              return even;
         private static boolean isNumber(char chara){
              boolean number=false;
              for(int i=0; i<=9; i++){
                   if((int)chara-48==i){
                        number=true;
              return number;
         private static boolean isValid(char chara){
              boolean valid=true;
              if(isNumber(chara)==true){
                   if(even(chara)==true)
                        valid=false;
              if((upperVowel(chara)==true)||(lowerVowel(chara)==true))
                   valid=false;
              return valid;
    }So in my test class i'd have something like this:
    public class test {
    public static void main(String[] args){
         NoVowelNoEven test1 = new NoVowelNoEven();
         NoVowelNoEven test2 = new NoVowelNoEven("hello 123");
         System.out.println(test1.getOriginal());
         //This prints hello   (default constructor string is "hello")
         System.out.println(test1.countValidChar(test1.getOriginal()));
         //This prints 3
         System.out.println(test1.getValidString());
         //This SHOULD print hll
    }

  • MSS 60.1.20: My Staff - Reporting: Trying to remove reports from tree list

    I am trying to remove (or I should say HIDE rather than remove) several of the SAP provided reports from the selection tree in the <b>MSS business package 60.1.20</b>. I checked the par file, and it appears that it relies on a function module, <b>HRWPC_RPT_FCODES_READ</b> which in turn calls <b>RH_MWB_FCODES_READ</b>, to build the tree structure based on function codes with scenario MSS0. I checked the IMG, and did not see any way of "hiding" these report/function codes through configuration. I assume I can delete the entries, but I do not want to do that. I would like to hide them. I noticed in the function module, that it refers to a hidden SAP structure <b>HRUSMWBFCH</b> that will exclude codes from the report tree.
    <b>Can anyone tell me how I should be hiding reports from the report tree?</b>

    I think I may have found the answer. In the IMG, you can go to Personnel Management -> Manager's Desktop -> Enhancement of Function Codes -> Define Structure of Function codes -> Change Arrangement of Function Codes.
    From here enter the scenario, higher level function code, and level number in the table. Be sure to check the box "function code hidden" to hide the item from the list.
    I had done this before, but the change did not appear within the portal. I had to actually refresh my browser cache by logging off and back on to the portal in order to see the changes.

  • I downloaded music onto my iPhone 4S from from the iTunes Store that I previously purchased, and now I can't delete them from my phone.  I tried do remove them from my MAC too, but still can't delete them.

    I downloaded music onto my iPhone 4S from from the iTunes Store that I previously purchased, and now I can't delete them from my phone.

    How are you trying to delete the music direct on your iPhone?
    You tried to remove the music from iTunes on your Mac how?
    Do you have Sync Music selected under the Music tab for your iPhone sync preferences with iTunes on your computer?

  • I am trying to remove firefox from my computer, it tells me I have to shut down firefox first. how do i shot off firefox

    I am trying to remove fire fox because I have had nothing but problems since I upgraded to the latest version. I have not been able to view attachments etc.
    I am now trying to remove fire fox, an when i attempt to, it keeps telling me that fire fox has to be shut off, how do i shut off FF.
    Do you have a simple fix for my problems, if not please inform me hoe to remove FF I use both gmail and hotmail e-mail addresses

    It is not possible to install OS X 10.7.2 on a Mac with a G5 processor.
    In order for 10.7.2 to be installed you must have an Intel processor and not a PowerPC which G5 is. Please straighten out your information.
    Also the version of iPhoto you are attempt to run would be helpful.
    Allan

  • How can I remove vbCrLf from a string?

    How do I delete all instances of vbCrLf from a string?
    Thanks in advance.

    For reading lines from a text file try something along these lines:
    Dim tfr As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(My.Application.Info.DirectoryPath & "\backups.dat")
    Dim TheFileLines As New List(Of String)
    While Not tfr.EndOfStream
    TheFileLines.Add(tfr.ReadLine())
    End While
    tfr.Close()
    tfr.Dispose()

  • Help! Trying to remove text from an already saved image

    I accidently saved an image with my watermark & now the image is locked & also saved as a jpeg image.  I can't remove the text without stamping it out or just starting over.  Does anyone know how to remove text from an image that has already been saved?

    You could have saved it before closing the image. As long as the image is open in Editor, we can always go back to the original position and get back the original file.
    In case you have closed, check if you have saved it as a version set. If your file name contains "edited-1" something, you have the file preserved.
    Otherwise, if you have replaced the file without having any copy of it anywhere else, you cannot revert the changes.

  • How do I remove whitespace from a template header

    I am trying to work myself thru understanding html coding by using a dreamweaver template and creating a page for my company. I have used dreamweaver before CC, however I am trying to understand the new changes.
    I ran into a problem I am hoping to get help with.
    I tried swapping out a placeholder logo on the template with my own logo. I seem to have a bit of white space at the bottom of the logo when I see it in live view or a browser. How can I get rid of it. I tried combinations of 0 margins and changing padding, but it seems I'm just whistling in the dark. Here is the code:
    The CSS associated with this page is here:
    @charset "UTF-8"; body {   font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;   background-color: #42413C;   margin: 0;   padding: 0;   color: #000; } /* ~~ Element/tag selectors ~~ */ ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */   padding: 0;   margin: 0; } h1, h2, h3, h4, h5, h6, p {   margin-top: 0; /* removing the top margin gets around an issue where margins can escape from their containing block. The remaining bottom margin will hold it away from any elements that follow. */   padding-right: 15px;   padding-left: 15px; /* adding the padding to the sides of the elements within the blocks, instead of the block elements themselves, gets rid of any box model math. A nested block with side padding can also be used as an alternate method. */ } a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */   border: none; } /* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */ a:link {   color: #42413C;   text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */ } a:visited {   color: #6E6C64;   text-decoration: underline; } a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */   text-decoration: none; } /* ~~ This fixed width container surrounds all other blocks ~~ */ .container {   width: 960px;   background-color: #FFFFFF;   margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */ } /* ~~ The header is not given a width. It will extend the full width of your layout. ~~ */ header {   background-color: #A36BE8; } /* ~~ These are the columns for the layout. ~~ 1) Padding is only placed on the top and/or bottom of the block elements. The elements within these blocks have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the block itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the block element and place a second block element within it with no width and the padding necessary for your design. 2) No margin has been given to the columns since they are all floated. If you must add margin, avoid placing it on the side you're floating toward (for example: a right margin on a block set to float right). Many times, padding can be used instead. For blocks where this rule must be broken, you should add a "display:inline" declaration to the block element's rule to tame a bug where some versions of Internet Explorer double the margin. 3) Since classes can be used multiple times in a document (and an element can also have multiple classes applied), the columns have been assigned class names instead of IDs. For example, two sidebar blocks could be stacked if necessary. These can very easily be changed to IDs if that's your preference, as long as you'll only be using them once per document. 4) If you prefer your nav on the left instead of the right, simply float these columns the opposite direction (all left instead of all right) and they'll render in reverse order. There's no need to move the blocks around in the HTML source. */ .sidebar1 {   float: right;   width: 180px;   background-color: #C5C2B8;   padding-bottom: 10px; } .content {   padding: 10px 0;   width: 780px;   float: right; } /* ~~ This grouped selector gives the lists in the .content area space ~~ */ .content ul, .content ol {   padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */ } /* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */ nav ul{   list-style: none; /* this removes the list marker */   border-top: 1px solid #666; /* this creates the top border for the links - all others are placed using a bottom border on the LI */   margin-bottom: 15px; /* this creates the space between the navigation on the content below */ } nav li {   border-bottom: 1px solid #666; /* this creates the button separation */ } nav a, nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */   padding: 5px 5px 5px 15px;   display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */   width: 160px;  /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */   text-decoration: none;   background-color: #15EE00; } nav a:hover, nav a:active, nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */   background-color: #ADB96E;   color: #FFF; } /* ~~ The footer ~~ */ footer {   padding: 10px 0;   background-color: #CCC49F;   position: relative;/* this gives IE6 hasLayout to properly clear */   clear: both; /* this clear property forces the .container to understand where the columns end and contain them */ } /*HTML 5 support - Sets new HTML 5 tags to display:block so browsers know how to render the tags properly. */ header, section, footer, aside, article, figure {   display: block; } 
    Thank you for your help!

    Try this -
    <img src="assets/jpgs/Prodigy Logo Large 2014.jpg" width="180" height="180" alt="" style="display:block;">
    What you are seeing as whitespace is the space reserved for glyph descenders on any element that is rendered within a text box (i.e., an inline element). By making the image "display:block" you eliminate that space because a block element doesn't have descenders. If that works to your satisfaction then you can give the logo an id, and create a CSS selector containing that block style.

  • How to remove "\r" from a string

    I have a string, it has "\r" and "\n" eg : "abcde dfs \r \n acdsa \r\ncdaacdla"
    when I display this on a panel or print from panel, a box appears at the end, I think its because of \r characters.
    Is there any easy way to remove them.?
    please help thanks.

    sorry i dont which other replace you are talking
    about....btw i am using 1.3.xDon't worry, you'll evolve someday ;~)
    Just dump it into a StringBuffer, and page through and delete manually.
    String removeRs(String string)
       StringBuffer b = new StringBuffer(string.length());
       for(int x = 0 ; x < string.length() ; x++)
          if(string.charAt(x) != '\r')
             b.append(string.charAt(x));
       return b.toString();
    }

Maybe you are looking for