A short answer: you could use the String.replace() method to replace the 0 character with another character, or the replaceAll() method to replace it with an empty String.
But can you give me an example of what exactly you need to do? Where are you getting Strings with 0's in them?
A character with unicode value 0 is still 0, no matter how you write it.
OK, so, where are you getting these 0-terminated (or '\0'-terminated, if you insist I must type all those characters ) Strings from in the first place? They're not usual in Java, of course.
Sanju Thomas
Ranch Hand
Joined: Dec 29, 2004
Posts: 243
posted
0
I did it.
String str = resultSet.getString(1)
str = str.replace((char)0,(char)13);
Ernest Friedman-Hill
author and iconoclast
Marshal
Ah, some broken C code is putting NUL terminators into the database! Go whack somebody on the head.
john guthrie
Ranch Hand
Joined: Aug 05, 2002
Posts: 124
posted
0
using jakarta-commons-lang, you could also StringUtils.chop(string) to remove the last character (no matter what it is)
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Originally posted by Sanju Thomas: I did it.
String str = resultSet.getString(1)
str = str.replace((char)0,(char)13);
That doesn't remove the null character, but does replace it with the character of unicode 13.
To really just remove it, use
str = str.replaceAll("\\u00", "");
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus