Unicode的学名是”Universal Multiple-Octet Coded Character Set”,简称为UCS
不可见字符”/u200b”为 Unicode Character ‘ZERO WIDTH SPACE’ (U+200B),可用于内容标识,不占位数。html
echo $LANG能够显示出Linux系统的编码方式,通常默认为UTF-8。
在Linux终端中”/u200b”为不可见字符。为了显示出内容中加入的不可见字符,可将内容保存到文本中,利用less命令打开文本。java
less
1
|
less 与 more 相似,但使用 less 能够随意先后浏览文件,而 more 仅能向前移动,却不能向后移动,并且 less 在查看以前不会加载整个文件。
|
eg:linux
1
2
3
4
5
|
在查看日志时
grep xxxxxx info.log |less
以less分页显示的形式查看日志, 用less打开的日志能够展现出不可见字符
less info.log |grep xxxxxx
打开的日志没法展现出不可见字符
|
java中打印unicode的例子api
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import
static
org.assertj.core.api.Assertions.assertThat;
/**
* Created by wenjia3 on 16/12/1.
*/
public
class
unicode {
public
static
void
main(String[] args){
String contentOri=
"test unicode"
;
String content1=
"\u200b"
+ contentOri +
"\u200b"
;
String content2=
"\u0021"
+ contentOri +
"\u0021"
;
String str =
""
;
for
(
int
i =
0
; i < content1.length(); i++) {
int
ch = (
int
) content1.charAt(i);
if
(ch ==
'\u200b'
)
str += content1.charAt(i) +
"\\u"
+ Integer.toHexString(ch);
else
str += content1.charAt(i);
}
System.out.println(content1);
System.out.println(content2);
System.out.println(str);
assertThat(content1).as(
"不含有/U200B字符"
).contains(
"\u200b"
);
}
}
|
运行结果less
1
2
3
|
?test unicode?
!test unicode! ?
\u200btest unicode?\u200b
|
直接打印content一、content2,unicode字符会自动编译成当前标准输出的编码。即\u200b为不可见字符,\u0021为“!”。
能够利用charAt()在程序中进行转换,将字符的unicode值打印出来。编码