大多数ASCII控制字符是否已过时?

时间:2018-04-19 23:54:48

标签: ascii delimiter control-characters

\ x20下的大多数ASCII代码似乎完全过时了。他们今天一直在使用吗?他们是否可以被认为是#34;还是最好避免它们?

我需要一个分隔符来分组"行"在一起,为了这个目的而选择其中一个肯定会很好。

来自man ascii

    Oct   Dec   Hex   Char                        
    ----------------------------------------------
    000   0     00    NUL '\0'                    
    001   1     01    SOH (start of heading)      
    002   2     02    STX (start of text)         
    003   3     03    ETX (end of text)           
    004   4     04    EOT (end of transmission)   
    005   5     05    ENQ (enquiry)               
    006   6     06    ACK (acknowledge)           
    007   7     07    BEL '\a' (bell)             
    010   8     08    BS  '\b' (backspace)        
    011   9     09    HT  '\t' (horizontal tab)   
    012   10    0A    LF  '\n' (new line)         
    013   11    0B    VT  '\v' (vertical tab)     
    014   12    0C    FF  '\f' (form feed)        
    015   13    0D    CR  '\r' (carriage ret)     
    016   14    0E    SO  (shift out)             
    017   15    0F    SI  (shift in)              
    020   16    10    DLE (data link escape)      
    021   17    11    DC1 (device control 1)      
    022   18    12    DC2 (device control 2)      
    023   19    13    DC3 (device control 3)      
    024   20    14    DC4 (device control 4)      
    025   21    15    NAK (negative ack.)         
    026   22    16    SYN (synchronous idle)      
    027   23    17    ETB (end of trans. blk)     
    030   24    18    CAN (cancel)                
    031   25    19    EM  (end of medium)         
    032   26    1A    SUB (substitute)            
    033   27    1B    ESC (escape)                
    034   28    1C    FS  (file separator)        
    035   29    1D    GS  (group separator)       
    036   30    1E    RS  (record separator)      
    037   31    1F    US  (unit separator)        
    040   32    20    SPACE                       

3 个答案:

答案 0 :(得分:2)

First the easy part: There are no network transmission concerns in most modern systems. Current protocols handle almost any data - whether 7-bit ASCII, 8-bit ASCII, Unicode characters, image data or compiled programs - as binary data. That has not always been the case. Many older systems had issues transferring control codes and other "unprintable" characters and especially problems with 8-bit data. But those days are, fortunately, behind us. The one big exception is if you want to be able to copy/paste data via an HTML form - for that you want to leave out all control codes and other funny stuff.

You can, of course, make the format anything you like. However, some characters are still used pretty frequently:

000   0     00    NUL '\0' - does "nothing" but is hard for some text editors to handle
003   3     03    ETX (end of text) - Control-C - "break" in a lot of systems
007   7     07    BEL '\a' (bell) - Still makes a bell sound.
011   9     09    HT  '\t' (horizontal tab) - A lot of text editors and file formats use this to set a fixed number of spaces
012   10    0A    LF  '\n' (new line) - like it says
015   13    0D    CR  '\r' (carriage ret) - used instead of, or together with \n on many systems
021   17    11    DC1 (device control 1) - Control-Q - Resume transmission - XON
023   19    13    DC3 (device control 3) - Control-S - Pause transmission - XOFF
033   27    1B    ESC (escape) - Used for PCL and other printer control codes and plenty of other things 

Everything else is pretty much up for grabs. I would especially avoid NUL and XON/XOFF - they are sometimes hard to enter into a file - and BEL because typing a file with BEL can be noisy.

If you have a truly binary format then you can do anything you want. But if you want to have a mostly-human-readable format then limiting the control codes is a good idea.

答案 1 :(得分:0)

位模式-即数字化的数值-不会过时。 ASCII控制代码的标签反映了在各种上下文中的建议用法-串行通信,文本显示和打印,命令行编辑等。更好的文字处理器和文本编辑器已在其键盘命令中使用了所有这些代码。自1970年代以来,甚至更早的年代,就开始设置并允许将它们全部插入文件中。此类程序请注意不要将这些代码直接发送到屏幕。他们会解释换行符和制表符,有时还会解释其他内容,并以符号(例如,脱字符号“ ^ A”)或带下划线或方括号的符号来象征性地显示其他所有内容。如果您担心用户会将您的文件拖到屏幕上,请当然避免使用ESC和上面提到的其他一些内容。否则,请随意使用它们。

很久以前,我修补了WordStar,以使其在需要时将点矩阵打印机置于图形模式。使用WordStar,任何七位代码都可以放入图形数据中。像魅力一样工作。

答案 2 :(得分:0)

ASCII控制代码不是过时的。如今,它们的使用已不多了,因为使它们如此有用的技术已不再是主流技术,例如通信技术(USB,以太网,WiFi,3G及更高版本的蜂窝电话等)的技术改进以及集成技术的改进。电路制造(每平方毫米的组件增加,CPU架构的改进,诸如片上系统之类的组件的更小型化)以及协议的改进。

但是,在物联网世界中,影响这些代码设计的相同技术考虑因素仍然适用:

  • RAM和存储空间有限的小型处理器
  • 低速路径上的低带宽通信

有几种设计用于构造文本的ASCII控制代码。 Wikipedia topic C0 and C1 control codes, Basic ASCII control codes描述了分隔符控制代码FS(文件分隔符),GS(组分隔符),RS(记录分隔符)和美国单位分隔符。

可用作标记数据结构字段的定界符。如果使用 对于层次结构级别,US是最低级别(划分纯文本 数据项),而RS,GS和FS的划分水平越来越高 组由其下一级的项目组成。 Unix信息格式 使用美国,然后使用可选的换页和换行符来标记 节点的开始。[14]

MARC 21使用US作为子字段定界符,使用RS作为字段终止符,并且 GS作为记录终止符。[15]

在当前版本的IPTC 7901中,如果未将它们用于其他 为此,建议将US用作表格中的列分隔符, 在表中将FS称为“中央字段分隔符”,而将GS和RS 分别用于标记后面的空格或连字符减为 分别不中断或不中断(在字符集中不提供) 明确的NBSP和SHY字符)。2

另请参见RFC20, ASCII format for Network Interchange中的描述,其中将FS,GS,RS和US描述为:

FS(文件分隔符),GS(组分隔符),RS(记录分隔符)和US(单位分隔符):这些信息分隔符 可以以可选方式在数据内使用,但它们的 层次关系应为:FS是最包容的,然后 GS,然后是RS,最后是US。 (内容和长度 未指定文件,组,记录或单位。)

Wikipedia topic IPTC 7901描述了在新闻服务消息中使用控制字符,从1979年正式批准该协议开始,这听起来与RSS feed协议相似。可以从IPTC网站上以The IPTC Recommended Message Format, 1995的形式获得实际的规范。