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值打印出來。編碼