Is there an invisible character that is not considered a space?

I work with an existing framework where I need to set some attribute to empty if certain conditions are met. Unfortunately, the framework does not allow setting only the whitespace value for the attribute value. In particular, he performs

!(org.apache.commons.lang.StringUtils.isBlank(value)) check the value

Is it possible to somehow get around this and set a value that looks empty / invisible to the eye but is not considered a space?

I'm using a dash “-” right now, but I think it would be interesting to know if this is possible.

+18
java whitespace
source share
2 answers

Try the Unicode Character 'ZERO WIDTH SPACE' (U + 200B) . This is not a space according to WP: space # Unicode

The StringUtils.isBlank code does not bother him:

 public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } 
+21
source share

This Unicode character 'ZERO WIDTH SPACE' (U + 200B) shared by Michael Konetska did not work for me, but found another that worked:

‏‏‎ ‎

It is actually identified as a combination

 U+200F : RIGHT-TO-LEFT MARK [RLM] U+200F : RIGHT-TO-LEFT MARK [RLM] U+200E : LEFT-TO-RIGHT MARK [LRM] U+0020 : SPACE [SP] U+200E : LEFT-TO-RIGHT MARK [LRM] 

and the ASCII value is 8207

‏‏‎'‏‏‎ ‎'.charCodeAt(0) // 8207

Source: http://emptycharacter.com/

0
source share

All Articles