Ignore trailing NULL characters when converting string from char array

user43968 :

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?

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

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=115266&siteId=1