GeeCON Prague 2014*
The moose likes Java in General and the fly likes character representation of a blank space Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "character representation of a blank space" Watch "character representation of a blank space" New topic
Author

character representation of a blank space

Vinod Awar
Ranch Hand

Joined: Nov 06, 2006
Posts: 125
Hi all,

what is the character representation of a blank space?
Iam trying to remove commas from a String
for ex:
String oldString="2,8764";
I can replace using String.replace(String,String) method.
but our client uses jdk1.3. So i need to use String.replace(char,char) method.

The resulting string should be like this "28764" (note:there should not be any space between).

Thanks,
Vinod


The biggest bankruptcy is the loss of enthusiasm
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by Vinod Awar:
Hi all,

what is the character representation of a blank space?
Iam trying to remove commas from a String
for ex:
String oldString="2,8764";
I can replace using String.replace(String,String) method.
but our client uses jdk1.3. So i need to use String.replace(char,char) method.

The resulting string should be like this "28764" (note:there should not be any space between).

Thanks,
Vinod


This link will answer your question.
Vinod Awar
Ranch Hand

Joined: Nov 06, 2006
Posts: 125
I have read the documentation. There is only one method for replacing.
i.e replace(char,char). How can i get the same result as this:
String oldStr="2,756";
oldStr=oldStr.replaceAll(",","");

using the replace(char,char) method of java 1.3

Thanks,
Vinod
Petrus Pelser
Ranch Hand

Joined: Feb 20, 2006
Posts: 132
Try replace(',', '')
Vinod Awar
Ranch Hand

Joined: Nov 06, 2006
Posts: 125

Try replace(',', '')


gives compilation error: Invalid Character constant
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by Vinod Awar:


gives compilation error: Invalid Character constant


you have to try



Here \u0020 represent space
Vinod Awar
Ranch Hand

Joined: Nov 06, 2006
Posts: 125

replaceAll(",","\u0020")

But it replaces "," with a space.

it is not the same as replaceAll()..

output:
str:#BC 2,84,56
str:#BC 2 84 56
str:#BC 28456

See the third line there is no space between numbers.
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Hai pal,
Now i got confused with your requirement

Please let me get your requirements correct,you need all "," in the String to be replaced or removed?

My assumption was that

Source String: "2,8456"
Final String: "2 8456" (this is just replacement)

If you want to remove the "," from your string like this following case

Source String: "2,8456"
Final String: "28456" (this is removal)

then your code should be like this

[ January 31, 2008: Message edited by: Balasubramanian Chandrasekaran ]
Vinod Awar
Ranch Hand

Joined: Nov 06, 2006
Posts: 125
Thanks Balasubramanian
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3606
    
  15
Or you could use a StringBuffer - it's charAt() and deleteCharAt() methods could be used in a loop to do what you need. This has the advantage of not creating lots of String objects (each call to substring and concat will create a new String), although for short Strings with few commas, it's probably not that much of a problem.

If you use Balasubramanian's code you will need to change the last but one line to
s = s.trim();


Joanne
 
GeeCON Prague 2014
 
subject: character representation of a blank space