How to ignore extra fields for fmt.Sprintf

后端 未结 5 1082
天涯浪人
天涯浪人 2021-01-13 13:24

I have a Golang program that reads a string parameter from command line and passes it to the fmt.Sprintf function. Let\'s say tmp_str is the target string from command line.

5条回答
  •  长情又很酷
    2021-01-13 13:51

    In this particular case, you could require the command line users to always supply a %s verb, and explain they can truncate the string to zero length:

    Hello Friends%.0s
    

    or even shorter:

    Hello Friends%.s
    

    The output is plain:

    Hello Friends

提交回复
热议问题