V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
checgg
V2EX  ›  程序员

\002 究竟是个什么东西?

  •  
  •   checgg · 2017-12-28 16:18:40 +08:00 · 4811 次点击
    这是一个创建于 2283 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2017-12-29 09:23:05 +08:00
    geelaw
        1
    geelaw  
       2017-12-28 16:22:41 +08:00
    riggzh
        2
    riggzh  
       2017-12-28 16:23:47 +08:00
    \0 转义了啊
    checgg
        3
    checgg  
    OP
       2017-12-28 16:58:23 +08:00
    @riggzh
    @geelaw

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

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

    有趣的是,你惟有在 MySQL 里不计算 \002 的长度。
    checgg
        5
    checgg  
    OP
       2017-12-28 17:10:22 +08:00
    @geelaw 谢谢
    linnil
        6
    linnil  
       2017-12-28 17:17:12 +08:00
    进行了转义, mysql 中'\0'就是 NUL 字符
    hl
        7
    hl  
       2017-12-28 17:33:51 +08:00
    anthow
        8
    anthow  
       2017-12-29 09:23:05 +08:00
    the character \002 is the octal code for ^B
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5330 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 89ms · UTC 08:27 · PVG 16:27 · LAX 01:27 · JFK 04:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.