Sanju Thomas
,
Ranch Hand
May 06, 2005 04:15:00
Hi all, Can any one tell me how to remove '\0' from the String .
Ernest Friedman-Hill
,
author and iconoclast
staff
May 06, 2005 06:18:00
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?
Sanju Thomas
,
Ranch Hand
May 06, 2005 08:49:00
I was not asking about '0' in String, rather '\0' in the String. while using '\0' terminated strings as parameters for the PreparedStatement in the JDBC query, I am getting this exception. java.lang.IllegalArgumentException: \0 not allowed I was asking on that context. I need remove '\0' not '0' Thank you for your replay. Hope now you understand my question.
Ernest Friedman-Hill
,
author and iconoclast
staff
May 06, 2005 09:08:00
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
May 06, 2005 09:10:00
I did it. String str = resultSet.getString(1) str = str.replace((char)0,(char)13);
Ernest Friedman-Hill
,
author and iconoclast
staff
May 06, 2005 09:31:00
Ah, some broken C code is putting NUL terminators into the database! Go whack somebody on the head.
john guthrie
,
Ranch Hand
May 06, 2005 12:27:00
using jakarta-commons-lang, you could also StringUtils.chop(string) to remove the last character (no matter what it is)
Ilja Preuss
,
author
staff
May 07, 2005 05:30:00
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", "");
Sanju Thomas
,
Ranch Hand
May 09, 2005 04:03:00
Thank You Guys.
My, my, aren't you a big fella. Here, have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com