Remote white space from string

Hi I need a method which will remove the spaces in a string eg "Hello World" -> "HelloWorld"
I have the code below but it dosnt work for the obvious reason charAt() returns a char and im comparing to a string.
Can anyone offer any help? Thanks
          public void removeSpace(String s)
          {     int rs = s.length();
               String cat;
               for (int i=0;i<rs;i++) {
                    cat = s.charAt(i).toString();
                    if (cat==" ") {
                         s.replace(""," ");
          }

Hi I need a method which will remove the spaces in a
string eg "Hello World" -> "HelloWorld"
I have the code below but it dosnt work for the
obvious reason charAt() returns a char and im
comparing to a string.
Can anyone offer any help? Thanks
          public void removeSpace(String s)
          {     int rs = s.length();
               String cat;
               for (int i=0;i<rs;i++) {
                    cat = s.charAt(i).toString();
                    if (cat==" ") {
                         s.replace(""," ");
Hi,
You can't modify the contents of a String, you must create a new String, and use that one. Your code should be:
public String removeSpace(String s) {
    return s.replaceAll(" ", "");
}The returned string is the string without spaces.
/Kaj

Similar Messages

  • How do I remove the white space from the bottom and side of my document?

    How do I remove the white space from the bottom and side of my document? (I'm not talking about printing, just viewing it on the screen.) There are about 6 inches of white space at the bottom and at the right hand side. I don't like this. On a blank new spreadsheet it's triple that amount of white space.

    The infinite canvas convention doesn't make a lot of sense for Numbers. When I'm viewing a spreadsheet and mistakenly scroll into white, empty space I think, "this is ridiculous - all of my content is fits on one screen. there's nothing over there."
    A (relatively) infinite canvas is logical for Microsft Excel because it's one big table. There are 256(?) columns by default and hundreds of rows on a sheet - there are cells outside what a user is looking at to see. However, when viewing a Numbers spreadsheet with a single 10 column 10 row table that fits on the screen, there's nothing else on it to scroll to.
    Numbers should distinguish between viewing a spreadsheet and editing one. When I'm just viewing, when there's no content outside the window it shouldn't scroll there. This window behavior is beyond annoying for Numbers on my iPad and iPhone.
    (Adding user-defined canvas size setting to my view mode / edit mode thinking would probably be the most complete solution to this now that I think about it.)
    Until now the way scrolling worked in Numbers has defied logic. Actually it still does lol. That said, thank you Yellowbox for providing a clear explanation. Much appreciated.

  • Adding white spaces between strings during concatenation in JSTL

    Please provide a way to add white space between strings during concatenation in JSTL.
    I tried the following.
    eg:
    <c:set var="even_odd" value="odd">
    <c:out value="first ${even_odd}"/>
    I want the output string as "first odd ".
    Moreover i am using the above value for generating the class attribute of a row of a table like
    <tr class=<c:out value="first ${even_odd}"/>>
    while printing the value of <c:out value="first ${even_odd}"/> in the page,i am getting correctly as i needed as "first odd".
    But while taking the code of the page while rendering by the browser, it is showing like
    <tr class="first" odd="">
    I think the white space is the problem.
    Please provide any solution or hint.

    <tr class=<c:out value="first ${even_odd}"/>><tr class="first ${even_odd}">

  • Is it possible to exclude white space from creating records using UNPIVOT

    SELECT
            FROM
                Table1
                UNPIVOT EXCLUDE NULLS
                    NEW_COLUMN
                    FOR COLUMN_NAME IN
                       FIELD1, field2, --------------FIELD20
                )I don't want to create row for whitespace (empty value) in any of field1-field20 columns. Row should create for each of value present in any of FIELD1-FIELD20. Is it possible to exclude white space from creating records using UNPIVOT? I am just looking for syntax if there any. thanks

    Hi,
    Sorry, it's very unclear what you want.
    Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Have you tried the the UNPIVOT EXCLUDE NULLS option? See the SQL Language manual for details.
    It that doesn't do what you want, then you may need to UNPIVOT in a sub-query, generating more rows than you want, and use a WHERE clause in the main query to remove the unwanted rows.

  • Stripping extra white space from a string

    I am trying to strip extra spaces from a string, so it there are 2 or more spaces between a word I want to remove all but one. I am trying the following code
    getStringTwo().replaceAll("/\s+/is","");
    but all I get is an error saying Invalid escape sequence
    Thanks
    G

    >
    This strips out all the whitespace. I ended up
    getting round it by walking through the string and
    checking the values of each char and comparing that
    to the next value. What a wast of effortt A small modification of my earlier post gives -
    public class Test040320a
        public static void main(String[] args)
            String str = "this    is       a \t test";
            str = str.replaceAll("\\s+"," ");
            System.out.println(str);
    }

  • Search for White space within strings

    create table emp_dtl
    (empname varchar2(23));
    Insert into emp_dtl values ('WAYNE');
    Insert into emp_dtl values ('JOSEPH KRUPP');     --------- has white space
    Insert into emp_dtl values ('YING ZONG LEE');    --------- has white space
    Insert into emp_dtl values ('COHEN');
    Insert into emp_dtl values ('MARIE');How can i search for empnames which has White space in it? From other OTN threads, I gathered that this has something to do with
    chr(32)But i don't know how to put this in LIKE operator.

    Hi,
    SELECT  *
    FROM    emp_dtl
    WHERE   REGEXP_LIKE (empname, '\s')
    ;will look for any kind of whitespace (including spaces, which are CHR (32)).
    It may be more efficient to specifically list all the different whitespace characters, and see if the string changes when you remove all of them:
    SELECT     *
    FROM     emp_dtl
    WHERE     empname != TRANSLATE ( empname
                           , 'x ' || CHR (9)     -- CHR (9)  = <tab>
                                          || CHR (10)     -- CHR (10) = <newline>
                                 || CHR (13)     -- CHR (13) = <return>
                           , 'x'
    ;Edited by: Frank Kulash on Jul 12, 2010 8:47 AM

  • How to remove white spaces from XML content using Coldfusion?

    Hi,
    Can anybody help me in removing white spaces in between the tags from the below XML content using coldfusion?
    XML content:
    <?xml version="1.0" encoding="UTF-8"?> <chart showdates="true" today="08/12/2009"> <phases> <phase color="CCFFCC" name="Funded"/> <phase color="CDCD67" name="Concept"/> <phase color="99CCFF" name="Feasibility"/> <phase color="0099FF" name="Development"/> <phase color="0099FF" name="Development"/> <phase color="CC99FF" name="Close-out"/> <phase color="909090" name="Sustaining"/> </phases><program name=""> <project enddate=" 30/03/2007 " id="43250" startdate=" 28/02/2006 "> <version enddate=" 30/03/2007 " number=" 1" startdate=" 28/02/2006 "> <phase color="CCFFCC" currentdate="23/03/2006" name="Project Start" plandate="28/02/2006" type="phase"/> <phase color="99CCFF" currentdate="04/04/2006" name="Feasibility Closure" plandate="31/05/2006" type="phase"/> <phase color="0099FF" currentdate="29/03/2007" name="Commercialization" plandate="30/12/2006" type="phase"/> <phase color="CC99FF" currentdate="30/03/2007" name="Project Closed" plandate="30/03/2007" type="phase"/> <phase color="909090" currentdate="" name="Obsolescence" plandate="" type="phase"/> </version> </project> </program> </chart>
    Output I am expecting is like below,
    <?xml version="1.0" encoding="UTF-8"?><chart showdates="true" today="08/12/2009"><phases><phase color="CCFFCC" name="Funded"/><phase color="CDCD67" name="Concept"/><phase color="99CCFF" name="Feasibility"/><phase color="0099FF" name="Development"/><phase color="0099FF" name="Development"/><phase color="CC99FF" name="Close-out"/><phase color="909090" name="Sustaining"/></phases><program name=""><project enddate=" 30/03/2007 " id="43250" startdate=" 28/02/2006 "><version enddate=" 30/03/2007 " number=" 1" startdate=" 28/02/2006 "><phase color="CCFFCC" currentdate="23/03/2006" name="Project Start" plandate="28/02/2006" type="phase"/><phase color="99CCFF" currentdate="04/04/2006" name="Feasibility Closure" plandate="31/05/2006" type="phase"/><phase color="0099FF" currentdate="29/03/2007" name="Commercialization" plandate="30/12/2006" type="phase"/><phase color="CC99FF" currentdate="30/03/2007" name="Project Closed" plandate="30/03/2007" type="phase"/><phase color="909090" currentdate="" name="Obsolescence" plandate="" type="phase"/></version> </project></program></chart>
    Thanks in advance,
    Regards,
    Manoz.

    Daverms,
    Thanks for the quick turn around..
    I have applied the solution what you suggested above (<cfprocessingdrirective suppresswhitespaces="yes"), still whitespaces are existing in my output.
    The output what I am getting is,
    (blue color part is my output & red color indicates whitespaces)
    <?xml version="1.0" encoding="UTF-8"?>
    <chart showdates="true" today="09/12/2009">
    <phases>
    <phase color="CCFFCC" name="Funded"/>
    <phase color="CDCD67" name="Concept"/>
    <phase color="99CCFF" name="Feasibility"/>
    <phase color="0099FF" name="Development"/>
    <phase color="0099FF" name="Development"/>
    <phase color="CC99FF" name="Close-out"/>
    <phase color="909090" name="Sustaining"/>
    </phases>
    <program name="">
    <project enddate=" 01/01/2010 " id="12059" startdate=" 20/06/2003 ">
    <version enddate=" 01/01/2010 " number=" 1" startdate=" 20/06/2003 ">
            <phase color="CCFFCC" currentdate="20/06/2003" name="Project Start" plandate="20/06/2003" type="phase"/>
            <phase color="CDCD67" currentdate="" name="Concept Closure" plandate="" type="phase"/>
            <phase color="99CCFF" currentdate="20/06/2003" name="Feasibility Closure" plandate="20/06/2003" type="phase"/>
            <phase color="F0FF00" currentdate="" name="Alpha Test" plandate="" type="milestone"/>
            <phase color="F0FF00" currentdate="26/07/2004" name="Beta Test" plandate="31/05/2004" type="milestone"/>
            <phase color="0099FF" currentdate="29/06/2005" name="Commercialization" plandate="08/12/2004" type="phase"/>
            <phase color="CC99FF" currentdate="24/02/2006" name="Project Closed" plandate="01/01/2010" type="phase"/>
            </version>
    <subproject enddate=" 16/10/2008 " id="11809" name="espWatcher Pricing Toolkit" startdate=" 01/08/2003 ">
    <version enddate=" 16/10/2008 " number=" 1" startdate=" 01/08/2003 ">
            <phase color="CCFFCC" currentdate="01/08/2003" name="Project Start" plandate="01/08/2003" type="phase"/>
            <phase color="99CCFF" currentdate="" name="Feasibility Closure" plandate="" type="phase"/>
            <phase color="0099FF" currentdate="15/06/2005" name="Commercialization" plandate="08/12/2004" type="phase"/>
            <phase color="CC99FF" currentdate="16/10/2008" name="Project Closed" plandate="16/10/2008" type="phase"/>
            </version>
    </subproject>
    <subproject enddate=" 31/12/2070 " id="35704" name="espWatcher version 2 (2005)" startdate=" 01/01/2005 ">
    <version enddate=" 31/12/2070 " number=" 1" startdate=" 01/01/2005 ">
            <phase color="CCFFCC" currentdate="01/01/2005" name="Project Start" plandate="01/01/2005" type="phase"/>
            <phase color="99CCFF" currentdate="01/07/2005" name="Feasibility Closure" plandate="01/07/2005" type="phase"/>
            <phase color="0099FF" currentdate="31/03/2006" name="Commercialization" plandate="31/03/2006" type="phase"/>
            <phase color="CC99FF" currentdate="31/12/2070" name="Project Closed" plandate="31/12/2070" type="phase"/>
            </version>
    </subproject>
    </project>
    </program>
    </chart>
    However this solution removes most of the whitespaces, I want exact output as flash file is expecting so..
    Where ever I am calling the CF functions, there I am getting the whitespaces. like below cases.
    startdate="#getProjectStartDate(sProjectIdList)#" -> output I am getting for this statement is -> " 12/09/2009 "
    Please assist me...
    Regards,
    Manoz.

  • Extra White Space from Hidden Menu Bar

    This seems to be a problem introduced by LV 2013. I have a VI that runs with the menu bar hidden. When I hit ctrl-m to see how it looks in run mode, it looks fine. When I run the VI, instead of fully hiding the menu bar, it leaves white space. This only seems to be a problem when the VI is the top level. When the VI is opened from another VI, it looks fine. I've attached screenshots when the VI is running as a top level, ctrl-m is used and running when launched from another VI. This was not an issue in LV 2012. It's only been a problem since switching to 2013.
    Solved!
    Go to Solution.
    Attachments:
    Settings Screen Running Dev.png ‏86 KB
    Settings Screen CTRL-m.png ‏84 KB
    Setting Screen - Launch as SubVI.PNG ‏107 KB

    Greetings thutch79,
    I replicated the settings shown at Window Appearance Dialog.png on a new VI, ran it, and did not reproduce the problem.
    I wonder if you experience the same behavior with a new VI? If not, you can copy paste the code to a new VI to fix a potential corruption issue.
    Regards,
    Alejandro | Academic Program Engineer | National Instruments
    Attachments:
    Window Appearance.JPG ‏119 KB
    Running VI.JPG ‏21 KB

  • Remove extra white space from an image

    I want to remove the extra white space in my image while writing it into a jpeg file using JPEGImageEncoder.
    Any help is welcome .

    ok.. Am having a JPanel whose width is set to 77000. But almost 60% of right hand side of the Panel is empty. I will create a BufferedImage from this component and then write it into a file using JPEGImageEncoder.
    The empty portion of the panel is coming as a white space in the image.
    Now how to remove this ? Was that clear enough ?

  • How to trim spaces from string in BMM layer?

    Hi friends,
    I need to trim spaces from the string. can you please give me syntax with example.
    Thanks

    Hi
    I have tried the below option , but it did not work . PS_D_PERSON
    PERSON_ID is char type in the data base oracle , and it is defined as varchar on the physical layer .
    So the table is loaded with space , i am not able to remove the space using trim both
    Thanks
    Sridhar.N

  • White spaces in strings

    how do i ignore the white space in a string.
    ex:
    String str = this is an example;
    how do i change it into
    String str2 = thisisanexample;

    I didn't mean to insult you or anything. I apologize if you took offence. It's just I am an old school C programmer myself and I when ever I work with Strings I have to remind myself that they are immutable objects with a extensive collection of methods not character arrays in which you can manipulate the characters indiviually. Of course there are no String or StringBuffer objects in C. I was simply referring to the process you recommeded of directly manipulating characters in a StringBuffer as being very C like thing to do. You can draw many parallels between working with a StringBuffer and a char array.
    Finally I don't have the code anymore. It was some time ago and it was just a test case for a specific problem I had not an exhaustive comparison between StringBuffers and String.replace(). Anyway for what its worth most String methods recast as StringBuffers for char manipulations in their implementations and do so quite efficiently. The average java programmer should avoid this practice themselves unless they have a specific need to do so because 9 out of 10 times they will do so less efficiently than the Java.lang.String implementors.
    To avoid this turning into any more of a flame war than it already is, I'll let you have the last word (i.e. I will not be adding anything further to this thread.)

  • How to extract ALL text on a line, including extra white space, from PDF?

    I have written my first scripts to parse thru PDF files and successfully locate the beginning and ending of text portions that I wish to copy/extract.  For example, one of the scripts reads thru PDF files and locates patterns that allow me to copy/extract a lengthy Title that spans several lines on the page.  My remaining problem is that sometimes the text I wish to copy/extract has tabs or lots of white space between the words, and I need to retain ALL the "white space" between words.  Basically, I am successful at using getPageNthWord(j, i, false) along with "Quad coordinate sets" to get a word-at-a-time for all the words on the multiple lines but it seems to be skipping over the tabs and extra white spacing beetween the words.   Another way to say this is that I need to extract/copy a full line at a time, including all white space, instead of being limited to just a word at a time. 
    Can anyone help me with an algorithm to extract/copy text, not just the words but also including tabs and other extra white space characters? Is there some type of Regular Expression I should be using, or maybe some additional parameter used for getPageNthWord that would retain all the extra white space?
    Thanks in advance,
    Ted L

    Did you try setting the bStrip parameter of getPageNthWord to false? It will
    preserve some of the whitespace, but not all of it.
    As far as I know, that's the only way to do it via a script.

  • How to auto-crop empty area (white space) from a scanned image

    I have a image scan operation thru' which the user can scan a A4-size paper, but the actual data on the scanned image is a small area.
    Any way that we can programatically crop the white area from the scanned image?
    Does JAI have any apis for doing this ?

    If you look at the constructor for BufferedImage, you can create an image of a size you specify. After creating the image, you can draw on it by obtaining its Graphics via the createGraphics() method. Now, you can draw the source image on the target image using something like
    imageGraphics.drawImage(sourceImage, 0, 0, targetImage.getWidth(), targetImage,getHeight, sourceUpperLeftX, sourceUpperLeftY, sourceUpperLeftX + targetImage.getWidth(), sourceUpperLeftY + targetImage.getHeight(), observer);
    now, your BufferedImage has the cropped image on it. Dispose of the graphics (good habit to release resources it used) and you are done.

  • White space connected from top to bottom

    I have a white space from top to bottom, but it does not reach the bottom at the Iphone-view. How can I fix this, I want the white space always form top to bottom.
    www.doormode.nl

    OK that makes more sense.  Vertical sounded like the 11" direction and it is hard to imagine a defect that would cause a repeating issue in that direction.  
    For this case I would suggest the troubleshooting steps shown here.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • Oo4o trailing white space

    Hi,
    I am using oo4o in ASP page, to select data from an Oracle 8.1.7 database. Using the Oradyanaset / Orasession.
    This works fine but I have a couple of queries where the data returned contains trailing white space. However, I have noticed that in my ASP code the data results are being returned from the Query with the white space trimmed.
    For example:
    'This is an example. ' - stored in database
    'This is an example.' - result returned.
    Is their a configuration or setting which I should use to keep the trailing white space from being trimmed.
    Any help would be much appreciated.
    Cheers.

    on the ORADC use the TrailingBlanks Property
    on the OraDynaset use the ORADYN_NO_BLANKSTRIP option when creating the dynaset.

Maybe you are looking for

  • Problem with calculate button in form

    hi all We have a problem when we try to calculate in a data form using the button of GUI. We receive a form syntax verification message "with impossible to verify the calculation:", scenario,year,entity. We don't have this error when we use the calcu

  • Column name of custom columns is possible of translating automatic

    In SharePoint 2013 is possible of translating automatic the column name of custom columns with machine translation services or it is necessary create resource files or source site and target site?

  • Last Date of the next month

    Hi, How to find the last date of the next month. Thanks in advance Sunitha

  • I can not compile successfully!

    I use jmf2.1.1 to capture audio data from mic,but the following code can not be complie successfully. I have added the jmf.jar and sound.jar in the classpath env variable. please help me with this problem thanks. Vector deviceList = CaptureDeviceMana

  • How to improve the video quality of jpg clips

    I am using several jpg stills in my sequence. They look like crap when I output to QT. Any suggestions?