Is there an invisible character that is not regarded as whitespace?

JavaWhitespace

Java Problem Overview


I am working with an existing framework where I have to set a certain attribute to blank if some conditions are satisfied. Unfortunately, the framework doesn't allow setting only whitespace to the attribute value. Specifically, it does a

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

Is it possible to somehow bypass this and set a value that looks blank/invisible to the eye but is not regarded as whitespace?

I am using a dash "-" right now, but I think it would be interesting to know if it's possible.

Java Solutions


Solution 1 - Java

There's also (U+2800 BRAILLE PATTERN BLANK), which is a blank Braille block rather than a space character.

Solution 2 - Java

Try [Unicode Character 'ZERO WIDTH SPACE' (U+200B)][1]. It is not a Whitespace according to [WP: Whitespace#Unicode][2]

The code of [StringUtils.isBlank][3] will not bother it:

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;
  }

[1]: http://www.fileformat.info/info/unicode/char/200B/index.htm "Unicode Character 'ZERO WIDTH SPACE' (U+200B)" [2]: http://en.wikipedia.org/wiki/Whitespace_character#Unicode [3]: http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/src-html/org/apache/commons/lang/StringUtils.html#line.231

Solution 3 - Java

That Unicode Character 'ZERO WIDTH SPACE' (U+200B) Michael Konietzka shared didn't work for me, but found a different one that did:

‏‏‎ ‎

It actually identifies as combination of

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 it's ASCII value is 8207

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

> Source: http://emptycharacter.com/

Solution 4 - Java

JavaScript's

String.fromCharCode(8287).repeat(30)

gave me real but invisible spaces.

http://emptycharacter.com/ great

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCodeBlueView Question on Stackoverflow
Solution 1 - Javauser4698348View Answer on Stackoverflow
Solution 2 - JavaMichael KonietzkaView Answer on Stackoverflow
Solution 3 - JavaBugs BunnyView Answer on Stackoverflow
Solution 4 - JavaJayantaView Answer on Stackoverflow