The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
billion

Go 语言 Printf 输出的字符串末尾被自动增加了一个百分号,如果去除?

  •  
  •   billion ·
    kingname · Dec 7, 2017 · 3530 views
    This topic created in 3106 days ago, the information mentioned may be changed or developed.
    fmt.Printf("请输入开始时间和结束时间。格式: %s startDate=2017-12-07 endDate=2017-12-10", os.Args[0])
    

    期望的输出内容为:

    请输入开始时间和结束时间。格式: ./mongo2mysql startDate=2017-12-07 endDate=2017-12-10
    

    但是实际上在 Linux 和 Mac 的终端输出的内容都是:

    请输入开始时间和结束时间。格式: ./mongo2mysql startDate=2017-12-07 endDate=2017-12-10%
    

    如何把末尾的百分号去掉?

    Supplement 1  ·  Dec 7, 2017
    本帖终结,是因为 zsh 的问题导致的。感谢各位回答。
    12 replies    2017-12-08 08:37:30 +08:00
    pathletboy
        1
    pathletboy  
       Dec 7, 2017
    linux 实测没有百分号。
    specita
        2
    specita  
       Dec 7, 2017
    mac 实测没有百分号
    lululau
        3
    lululau  
       Dec 7, 2017
    用的 zsh
    undeflife
        4
    undeflife  
       Dec 7, 2017
    这各百分号是终端显示的换行吧
    hguandl
        5
    hguandl  
       Dec 7, 2017
    这个貌似与终端有关,我在用 zsh 时就发现运行程序时如果输出末尾没有新的空行,会打出一个 % 作为提示。你可以尝试用输出重定向 > 将标准输出放到一个文件里,再打开看看是不是还有 %
    rrfeng
        6
    rrfeng  
       Dec 7, 2017 via Android
    我猜是终端检测到没有换行符所以现实的那个 %

    你加个 \n 试试
    lululau
        7
    lululau  
       Dec 7, 2017
    @hguandl zsh 是个 shell,并不是终端
    yonka
        9
    yonka  
       Dec 7, 2017
    这个 % 是你的终端的 prompt。
    原因是你这个少输出了个回车,所以输出内容跟新的 prompt 在同一行了。

    这里应该是:

    fmt.Printf("请输入开始时间和结束时间。格式: %s startDate=2017-12-07 endDate=2017-12-10\n", os.Args[0])
    billion
        10
    billion  
    OP
       Dec 7, 2017
    确实我有 zsh。可能是这个问题。
    6ufq0VLZn0DDkL80
        11
    6ufq0VLZn0DDkL80  
       Dec 7, 2017
    ...
    timothyye
        12
    timothyye  
       Dec 8, 2017 via Android
    哈哈哈
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   924 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 63ms · UTC 21:34 · PVG 05:34 · LAX 14:34 · JFK 17:34
    ♥ Do have faith in what you're doing.