處理字串偶然間遇到特殊字元ETX,STX,查了才知道原來是控制碼,一般控制碼是 ASCII 前 32 碼。在python官網有詳細的解釋。
程式:
# -*- coding: utf-8 -*-
#測試EXT STX
stx = '\x02'
etx = '\x03'
s='疵除外 )。",'
ustx=stx.encode('UTF-8')
uetx=etx.encode('UTF-8')
print s.find(etx)
print s.find(uetx)
print s.find(stx)
print s.find(ustx)
輸出:
9
9
-1
-1
| Name | Meaning | 
|---|---|
NUL | |
SOH | Start of heading, console interrupt | 
STX | Start of text | 
ETX | End of text | 
EOT | End of transmission | 
ENQ | Enquiry, goes with ACK flow control | 
ACK | Acknowledgement | 
BEL | Bell | 
BS | Backspace | 
TAB | Tab | 
HT | Alias for TAB: “Horizontal tab” | 
LF | Line feed | 
NL | Alias for LF: “New line” | 
VT | Vertical tab | 
FF | Form feed | 
CR | Carriage return | 
SO | Shift-out, begin alternate character set | 
SI | Shift-in, resume default character set | 
DLE | Data-link escape | 
DC1 | XON, for flow control | 
DC2 | Device control 2, block-mode flow control | 
DC3 | XOFF, for flow control | 
DC4 | Device control 4 | 
NAK | Negative acknowledgement | 
SYN | Synchronous idle | 
ETB | End transmission block | 
CAN | Cancel | 
EM | End of medium | 
SUB | Substitute | 
ESC | Escape | 
FS | File separator | 
GS | Group separator | 
RS | Record separator, block-mode terminator | 
US | Unit separator | 
SP | Space | 
DEL | Delete | 
參考:
https://docs.python.org/2/library/curses.ascii.html
沒有留言:
張貼留言