Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

948
Vistas
How to remove \u200B (Zero Length Whitespace Unicode Character) from String in Java?

My application is using Spring Integration for email polling from Outlook mailbox.

As, it is receiving the String (email body)from an external system (Outlook), So I have no control over it.

For Example,

String emailBodyStr= "rejected by sundar14-\u200B.";

Now I am trying to remove the unicode character \u200B from this String.

What I tried already.

Try#1:

emailBodyStr = emailBodyStr.replaceAll("\u200B", "");

Try#2:

`emailBodyStr = emailBodyStr.replaceAll("\u200B", "").trim();`

Try#3 (using Apache Commons):

StringEscapeUtils.unescapeJava(emailBodyStr);

Try#4:

StringEscapeUtils.unescapeJava(emailBodyStr).trim();

Nothing worked till now.

When I tried to print this String using below code.

logger.info("Comment BEFORE:{}",emailBodyStr);
logger.info("Comment AFTER :{}",emailBodyStr);

In Eclipse console, it is NOT printing unicode char,

Comment BEFORE:rejected by sundar14-​.

But the same code prints the unicode char in Linux console as below.

Comment BEFORE:rejected by sundar14-\u200B.

I read some examples where str.replace() is recommended, but please note that examples uses javascript, PHP and not Java.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Finally, I am able to remove 'Zero Width Space' character by using 'Unicode Regex'.

String plainEmailBody = new String();
plainEmailBody = emailBodyStr.replaceAll("[\\p{Cf}]", "");

Reference to find the category of Unicode characters.

  1. Character class from Java.

Character class from Java lists all of these unicode categories.

enter image description here

  1. Website: http://www.fileformat.info/

Character category

  1. Website: http://www.regular-expressions.info/ => Unicode Regular Expressions

Unicode Regex for \u200B character

Note 1: As I received this string from Outlook Email Body - none of the approaches listed in my question was working.

My application is receiving a String from an external system (Outlook), So I have no control over it.

Note 2: This SO answer helped me to know about Unicode Regular Expressions .

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda