Removing Spaces in a String

I have a string which has spaces in the middle eg.
String Temp = "Java Is Cool";
I want to know if there is a function which I can execute so that the result Temp is equal to "JavaIsCool"
Can anyone please help me....

There is no API function, but you can create one, using StringTokenizer to get the desired result:
import java.util.*;
public String deleteSpaces (String a) {
    StringTokenizer st = new StringTokenizer(a," ");
    StringBuffer sb=new StringBuffer();
    while (st.hasMoreElements()) {
        sb.append(st.nextToken());
    return sb.toString();
}

Similar Messages

  • To remove space between a string

    Hi all,
    Please help me to solve this.
    I have a String "Your current options"
    i want to remove all the blank spaces in between the string
    The final string should be "Yourcurrentoptions"
    Please respond..

    Please dont double post, its considered rude.
    Mel

  • Help :how to remove spaces in string

    could any body please help me in removing spaces from string suppose i have written vivek chhabra and i want to remove spaces in this string and want a string vivekchhabra then how this could be done
    anybody help me please
    vivek

    String string = "Hello - This is a test!";
    String result = string.replaceAll(" ", "");
    System.out.println(result);This code results the following output:
    Hello-Thisisatest!

  • How do I remove extra white spaces in a string?

    How do I remove extra white spaces in a string?
    trim() removes before and after spaces.
    If I have a string "This is Test"
    I want to remove extra spaces between words and also I want to keep SINGLE space
    between words. So output should be "This is Test". Thanks.

    replaceAll dosen't support with my version. Actually this works..............!!!!!!!!! Thank you.
                        java.util.StringTokenizer st = new java.util.StringTokenizer(brn, " \t");
                        StringBuffer buf = new StringBuffer();
                        while (st.hasMoreTokens()) {
                             buf.append(" ").append(st.nextToken());
                        String brn1 = buf.toString().trim();

  • How do I remove spaces or special characters within a cell for large amounts of data

    Is there any shortcut to remove spaces between words and numbers within a cell?
    Example:
    Current: .5 lt PET (6)
    Need: .5ltPET(6)
    Is there any shortcut to remove special characters between numbers within a cell?
    Example:
    Current: 0--000--000--0
    Need: 00000000

    Thanks Wayne.
    I have been away from using Numbers or Excel for 4-5 years so it is slowly coming back to me. I am get that I need to use the SUBSTITUTE function however I am having trouble with getting it to work.
    My Data
    ST PAULI 12/12 NR
    $27.16
    12oz NR(12)
    0--80660--95937--5
    ST PAULI 4/6/12 NR
    $28.76
    12oz NR(6)
    0--80660--95935--1
    ST PAULI DK 12/12 NR
    $0.00
    12oz NR(12)
    0--000--000--0
    ST PAULI DK 4/6/12 NR
    $28.76
    12oz NR(6)
    0--80660--95945--0
    ST PAULI N/A 4/6/12 NR
    $20.66
    12oz NR(6)
    0--80660--95955--9
    CAYMAN JACK 4/6/12 NR
    $29.12
    12oz NR(6)
    8--15829--01006--8
    CAYMAN JACK 8OZ/12PK CAN
    $23.18
    8oz CAN(12)
    8--15829--01061--7
    TGIF LIIT 10OZ FROZEN POUCH
    $35.80
    10oz POUCH(24)
    8--15829--01043--3
    TGIF MARGARITA 10OZ FROZEN POUCH
    $35.80
    10oz POUCH(24)
    8--15829--01047--1
    TGIF PINA COLADA 10OZ FROZEN POUCH
    $35.80
    10oz POUCH(24)
    8--15829--01045--7
    TGIF STRAWBERRY 10OZ FROZEN POUCH
    $35.80
    10oz POUCH(24)
    8--15829--01042--6
    BALLAST PT BIG EYE IPA 1/2 BBL
    $190.00
    KEG 1984oz (1/2 KEG)
    0--000--000--0
    BALLAST PT BIG EYE IPA 1/6 BBL
    $73.00
    KEG 660.1oz (1/6 KEG)
    0--000--000--0
    BALLAST PT BIG EYE IPA 4/6/12 CAN
    $33.00
    12oz CAN(6)
    6--72438--00052--7
    There are many more but this is enough to show you. I need to remove all spaces from the First and Third Columns. I need to remove all (--) from the fourth. Where do I put in the substitute function and what is source sting, existing-string, new-string, and occurrence.
    Thank You for your help.

  • Remove spaces from a variable

    I have a variable called 'enteredname':-
    var enteredname:String;
    When the user enters some text into my text input 'nameentry' and clicks a button the text entered is saved into this variable:-
    enteredname = nameentry.text;
    This variable is then sent to a server and set as the name of the item the user has added via http request however I want to add in another string variable 'enteredimagename' which will store the same text but will have any spaces removed or any characters that would not be appropriate to an image/jpeg file.
    The idea of this is that the user adds a name for an item their adding and the same name gets applied both as the items title and as the items image filename (with all the spaces etc removed) as all of the images in my app are stored on a server and are dynamic so the click would look something like:-
    enteredname = nameentry.text;
    enteredimagename = nameentry.text (with some code to remove the spaces for this string or something)
    Can anyone help me out with this?

    Hi use this function pass the name or any string that you want to remove strings..the function will return you the concatenated string without spaces.
    private function stripSpaces():String
        var strippedSpaces:String = StringUtil.trim(name);
        var strArray:Array = strippedSpaces.split(" ");
        var concatString:String = "";
        for(var i:int=0;i<strArray.length;i++)
         if(strArray[i] != " ")
          concatString += strArray[i];
        return concatString;   
    This function removes all spaces, also the spaces between words and at the beginning and end as well.
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • 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);
    }

  • Removing spaces in field

    Sorry for asking a very simple (hopefully) question.  Does anyone know how can remove spaces from a given field.  One of my field has the following:
    field1 = '      ABCD'.
    What command should I use so field1 would end up with just 'ABCD'?
    Thanks.

    Hi SS
    General templates for doing such operations on strings:
    SHIFT <c> LEFT DELETING LEADING <str>.
    SHIFT <c> RIGHT DELETING TRAILING <str>.
    where str can be SPACE or something like e.g: 'abc'
    Regards
    Ashish

  • Removing spaces in a value

    What is the easiest way to remove the spaces form a string or replace them with underscore i.e. change "The red car" to "Theredcar" or "Theredcar"?
    Thanks.
    Pedro

    I realize you have a lot of excellent responses to this question already!! Some serious AppleScript-gun-slinging going on in this thread, I like!!
    Just to throw another method into the mix:
    <pre style="margin:0px;padding:5px;border:2px dotted green;width:630px; height:auto;color:#ffffff;background-color:#000000;overflow-x:auto;overflow-y:h idden;font-family:Verdana, Monaco, monospace;font-weight:bold;font-size:12px;"
    title="Copy this text and paste it into your Script Editor application.">set theDog to display dialog "Enter the text to manipulate below:" default answer ¬
    "The red car" buttons ¬
    {"Cancel", "Remove Spaces", "Replace With Underscores"} default button 3
    set {theText, theButton} to {text returned of theDog, button returned of theDog}
    if theButton is "Remove Spaces" then
    set theDelimiter to ""
    else
    set theDelimiter to "_"
    end if
    do shell script "echo " & quoted form of theText & ¬
    "|awk 'gsub(\" \",\"" & theDelimiter & "\") {print}'"</pre>
    Now you've got plenty to choose from and all these different approaches serve their own great purpose!! Happy scripting! Remember, there are always many different ways to achieve the results you're looking for.

  • Removing spaces between characters using a loop

    How can I remove spaces between characters using a loop? I made a program that tests the validity of a social insurance number. However, I'd like to be able to remove the spaces in the input if the users sepeates their SIN using spaces. example (123 456 789 becomes 123456789)
    Thank you
    Edited by: umhodzic on Feb 10, 2008 2:43 PM

    umhodzic wrote:
    Thank you for your response. However, the procudre must be done using a loop.It doesn't have to be done using a loop, as already shown. However if you have some ignorant person telling you you have to have a loop, then here's a solution that uses a loop:String s = "123 456 789";
    while (s.contains(" ")) {
      s = s.replaceAll(" ", "");
    }

  • Delete white spaces between two strings

    hi!
    How do I remove white spaces between two strings. I have attached file for reference.
    Thanks
    Attachments:
    untitled4.JPG ‏62 KB

    You first need to define what you consider to be "whitespace". Is it just a space? Is it spaces and linefeeds? What about carriage returns? Tabs? Anything non-alphabetic and/or non-numeric?
    As mentioned previously, the Search and Replace String can be used to delete characters by wiring an empty string to the replace string input. The following, for example, will delete all spaces:
    If you need to delete other whitespace characters, just call it again on the resulting string.
    Message Edited by smercurio_fc on 06-02-2008 09:25 AM
    Attachments:
    Example_VI1.png ‏3 KB

  • PreparedStatement space and empty String

    Hi, I have this problem:
    PreparedStatement bookedQtyPS = null;
    String qry="SELECT * from djwsearch where djwitem=?;
    bookedQtyPS = conn.prepareStatement(qry);
    if(item.equals(""){ //item is an empty String
    bookedQtyPS.setString(1," "); // I set space instead of empty String
    }else{
    bookedQtyPS.setString(1,item);
    My problem is that I need to set space insteadOf empty String, but I think that I can not use PreparedStatement to do this. I have performance problems (my query is much more complicated than this one) so I choose PreparedStatement and not Statement.
    How can I do? Is this bug solved using PreparedStatement?
    Thanks.

    you can do it with the help of PreparedStatement.
    Here the type of field(djwitem) and setmethod is should be match..i mean if the type of ur field is String then you need to use the setSting method.
    you can do one thing specify one string variable.
    String space=" ";
    and now put this sapce variable at the second parameter of setString method.

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

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

  • How to remove space after paragrph in pages on ipad

    Can't figure out how to remove space after each paragraph in Pages for Ipad

    Settings > General > International > Region Format
    Set it to your country to format numbers and dates in the way your country does.

Maybe you are looking for

  • *URGENT HELP REQUIRED* java.sql.SQLException: Invalid Oracle URL specifed

    Hi all, In the middle of the last week for my final year project and having to convert to an Oracle database due to compatibility problems with university Tomcat Server and MS Access. I'm having trouble connecting to the Oracle database and would app

  • MS uninstall

    Gentlemen, I�ve just removed a MS installation that was being used to test some features of the product. It was registered in the production DS. We will now use a brand new machine for our mail server. Some entries from MS -- including the DC tree --

  • ISight with External Drive or Firewire Hub

    Hello, I am interested in purchasing an iSight for multiple reasons. I have been reading in the forum that iSight may not work with certain firewire devices which is unfortunate since I utilize external firewire devices on a daily basis and it would

  • Reader X, sandbox and SendMessage()

    Hi. How can I keep my plugin running under Reader X, without disabling the protected mode? At some point in my plugin code I use SendMessage() with WM_COPYDATA to send some data to my main proccess. My main process response to this message by poping

  • Death in the family - iPad unlock?

    I have a fairly strange question, but one that I'm sure some people have had to deal with. My girlfriend had a death in the family. This person had an iPad with the password lock turned on. Is there any way to unlock the device without erasing everyt