• 请不要在回答技术问题时复制粘贴 AI 生成的内容
checgg
V2EX  ›  程序员

\002 究竟是个什么东西?

  •  
  •   checgg · Dec 28, 2017 · 5323 views
    This topic created in 3064 days ago, the information mentioned may be changed or developed.

    python

    In [8]: print 'hehe' + '\002' + 'hehe'
    hehehehe
    
    In [9]: print len('\002')
    1
    
    

    php

    print 'hehe' . "\002" . 'hehe';
    print count("\002");
    
    hehehehe1
    
    

    mysql

    mysql> select concat('hehe',"\002",'hehe') as a;
    +------------+
    | a          |
    +------------+
    | hehe 02hehe |
    +------------+
    1 row in set (0.04 sec)
    

    为什么在 mysql 里面会不一样?

    8 replies    2017-12-29 09:23:05 +08:00
    geelaw
        1
    geelaw  
       Dec 28, 2017
    riggzh
        2
    riggzh  
       Dec 28, 2017
    \0 转义了啊
    checgg
        3
    checgg  
    OP
       Dec 28, 2017
    @riggzh
    @geelaw

    为什么你们都知道 mysql \0 会被转译我却不知道。。。
    geelaw
        4
    geelaw  
       Dec 28, 2017 via iPhone
    @checgg 这并不需要很渊博的知识,只需要基本的解决问题思路。

    若你看一下 mysql 的输出,就会发现它输出了一个空白和 02,而 \0 输出为空白是常见做法,自然想到可能是 MySQL 转义方式不同,搜索 mysql string escaping 就可以见到相关文档。

    有趣的是,你惟有在 MySQL 里不计算 \002 的长度。
    checgg
        5
    checgg  
    OP
       Dec 28, 2017
    @geelaw 谢谢
    linnil
        6
    linnil  
       Dec 28, 2017
    进行了转义, mysql 中'\0'就是 NUL 字符
    hl
        7
    hl  
       Dec 28, 2017
    anthow
        8
    anthow  
       Dec 29, 2017
    the character \002 is the octal code for ^B
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3616 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 04:39 · PVG 12:39 · LAX 21:39 · JFK 00:39
    ♥ Do have faith in what you're doing.