Home arrow static arrow Java Programming [Archive] - Empty character
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Empty character
This topic has 20 replies on 2 pages.    1 | 2 | Next »

Posts:49
Registered: 2/5/04
Empty character  
Jun 14, 2004 3:43 AM



 
Hi All,
Just help in solving this.
When I want an empty String I can declare it as
String str = "";
But when I want an empty character I cannot do it as char ch = '';

Agree.
Now can any body tell me how to get an empty character. I am going thru unicodes to find it out but it is consuming time. If anybody knows the unicode value of the empty Character or any other way to get an empty character please help me out.

Thanks in advance
Karthik
 

Posts:446
Registered: 6/23/00
Re: Empty character  
Jun 14, 2004 3:50 AM (reply 1 of 20)



 
Think you can use "\0" as empty character?
 

Posts:1,888
Registered: 22/08/01
Re: Empty character  
Jun 14, 2004 3:50 AM (reply 2 of 20)



 
An empty char unicode ?
isent that a contradiction ?
If you put a unicode in it, it isent empty !
 

Posts:49
Registered: 2/5/04
Re: Empty character  
Jun 14, 2004 3:59 AM (reply 3 of 20)



 
Think you can use "\0" as empty character?

Thanks for the reply but '\0' is representing a space.

My problem is that I want to remove spaces in between of a string.
For example if
String str = "ab st ra ct";
I want to make it as "abstract"

For this I am using str.replace(' ', ...)
method. I dont know what I have to pass as a second parameter

Karthik
 

Posts:1,995
Registered: 12/10/00
Re: Empty character  
Jun 14, 2004 4:02 AM (reply 4 of 20)



 
If you are using java1.4 or above you can use
String.replaceAll(" ", "");

Mike
 

Posts:49
Registered: 2/5/04
Re: Empty character  
Jun 14, 2004 4:03 AM (reply 5 of 20)



 
No I am using 1.3.1
thanx
 

Posts:446
Registered: 6/23/00
Re: Empty character  
Jun 14, 2004 4:07 AM (reply 6 of 20)



 
You can use method replaceAll(String, String) instead,
that does not require characters as parameter, but strings.
 

Posts:1,888
Registered: 22/08/01
Re: Empty character  
Jun 14, 2004 4:07 AM (reply 7 of 20)



 
switch to 1.4 or:

Use a Stringtokenzier with
" "
as tokendelimiter and concat all the tokens into a Stringbuffer.
 

Posts:49
Registered: 2/5/04
Re: Empty character  
Jun 14, 2004 4:11 AM (reply 8 of 20)



 
StringTokenizer or reding thru characters and appending if it is not a space are tiresome things to do.
I would like to use replace method to replace character

Switching can be done to 1.4 but I would like to have a solution with 1.3

Thanx
Karthik
 

Posts:446
Registered: 6/23/00
Re: Empty character  
Jun 14, 2004 4:15 AM (reply 9 of 20)



 
No I am using 1.3.1

then you might have to create a StringTokenizer(str, " ", false),
and concatenate all the tokens into one String.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html
 

Posts:446
Registered: 6/23/00
Re: Empty character  
Jun 14, 2004 4:19 AM (reply 10 of 20)



 
Do not hesitate to use StringTokenizer;
you will see it is not tiresome.
 

Posts:49
Registered: 2/5/04
Re: Empty character  
Jun 14, 2004 4:35 AM (reply 11 of 20)



 
I agree that it is not tiresome but if I have a direct method why should I do it manually.
String.replace will help me in removing the spaces but I would like to know how to initialize or how to represent an empty character.

Karthik
 

Posts:1,995
Registered: 12/10/00
Re: Empty character  
Jun 14, 2004 4:39 AM (reply 12 of 20)



 
I would like to know how to initialize or how to
represent an empty character.

And how do you represent any empty primitive?
char is not an Object, it's a primitive and always has some value.
String is a complex object that wraps character sequences and "" is a 0-length character sequence.

Mike
 

Posts:49
Registered: 2/5/04
Re: Empty character  
Jun 14, 2004 4:49 AM (reply 13 of 20)



 
Thats why I am going thru unicodes to find out whether we have an empty character representation
something like \u followed by 4 hexadecimal characters.
Do we have any unicode for this problem?

Karthik
 

Posts:2,909
Registered: 13.8.2003
Re: Empty character  
Jun 14, 2004 5:08 AM (reply 14 of 20)



 
There is no such thing as an "empty character" just like you don't have an empty int or an empty byte. String can be empty, but it's an Object so it's a whole different thing.

Now get your head out your *** and use the StringTokenizer.
 
This topic has 20 replies on 2 pages.    1 | 2 | Next »