51

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.

4

4 回答 4

41

试试Unicode Character 'ZERO WIDTH SPACE' (U+200B)。根据WP,它不是空格:Whitespace#Unicode

的代码StringUtils.isBlank不会打扰它:

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;
  }
于 2013-11-12T19:04:34.460 回答
38

还有(U+2800 BRAILLE PATTERN BLANK),它是一个空白盲文块,而不是一个空格字符。

于 2019-12-29T21:10:37.597 回答
7
于 2019-10-11T21:28:02.690 回答
1

JavaScript 的

String.fromCharCode(8287).repeat(30)

给了我真实但无形的空间。

http://emptycharacter.com/ great
于 2020-11-21T08:26:27.857 回答