Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove nul characters (\0) from string in Java

Tags:

java

I understand that this code in C# is trying to remove nul characters (\0) from a string.

string.Join("", mText.Split(new string[] { "\0" }, StringSplitOptions.None));

Is there any way to do that efficiently in Java?

like image 830
Sandah Aung Avatar asked Apr 08 '16 04:04

Sandah Aung


People also ask

How do I remove a null character?

A backslash followed by three 0's represents the null character. This just deletes these characters and writes the result to a new file.

How do you get rid of null in java?

string. replace("null", ""); You can also replace all the instances of 'null' with empty String using replaceAll. Save this answer.

What is the NUL character in java?

In programming languages/context, a null character is represented by the escape sequence \0, and it marks the end of a character string.

How do you replace NUL?

There are two ways to replace NULL with blank values in SQL Server, function ISNULL(), and COALESCE(). Both functions replace the value you provide when the argument is NULL like ISNULL(column, '') will return empty String if the column value is NULL.


1 Answers

You can write:

mText.replace("\0", "");
like image 135
ruakh Avatar answered Sep 20 '22 18:09

ruakh