java - Remove "empty" character from String -
I am using a framework which periodically returns a faulty string with "empty" characters. For example, "foobar": [, f, o, o, b, a, r]
The first character is not a white space (''), hence a system. Outprintin () "FOObar" and "FOOBR" will not come back. However, the length of the string is 7 instead of 6. Obviously this string methods (equivalent, split, substrung, ..) are useless. Is there a way to remove empty characters from a string?
I tried to create a new string like this:
stringbilder sb = new StringBuilder (); For (The last four characters: Perverted strings.overwater ()) {if (character. Defined (character)) {sb.append (character); }} Sb.toString ();
Unfortunately this does not work with the following code:
stringbilder sb = new stringbilder (); For (the last character character: Perverted strings.karkararere ()) {if (character! = Null) {sb.append (character); }} Sb.toString ();
I can not even check an empty character like this:
if (character == '') {//}
Obviously there is something wrong with the string .. But I can not change the structure that I am using or waiting to fix it (if it is within one of their structures Has bugs). I have to handle this string and do it the Senate.
Any thoughts?
It is probably shown by \ 0
you get rid of it Can get.
To dismiss the exact code point, do this:
for (four c: string.toCharArray ()) {System.out.printf ("U +% 04x ", (int) c); }
Then you can find the exact characters. According to the update:
Rather than leaving 95% of any UTF8 range, simply the category of valid characters Can you know how to get involved?
You can do this with the help of regex. Reply to @PoligenBelicants More here.
On the other hand, instead of fixing the problem you can fix it in its root. Either update the files to get rid of the BOM mark, this is a legacy method to distinguish the UTF-8 files from others that is useless nowadays, or use the reader
Recognizes and leaves. See also.
Comments
Post a Comment