Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore trailing NULL characters when converting string from char array

I am using a JNI API (that i can't change) that return a fixed size char array that represent a string.

I am converting it to String with String.valueOf(char [])

The problem is that i can receive an array like this {'a','b','c','\0','\0','\0'}

Using valueOf() keeps the trailing NULLs and a I get a wrong string.

Is there a simple way to convert such and array to string and removing NULLs?

like image 890
user43968 Avatar asked Oct 21 '25 15:10

user43968


1 Answers

String s = String.valueOf(bits).trim();

just trim the string it'll get rid of all *leading & *trailing white space.

like image 52
mavriksc Avatar answered Oct 23 '25 04:10

mavriksc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!