Home  >  Article  >  Backend Development  >  Golang string formatting

Golang string formatting

WBOY
WBOYforward
2024-02-09 11:00:09675browse

Golang 字符串格式化

php editor Baicao introduces Golang string formatting to you. In Golang, string formatting is a common operation, which can help us convert different types of data into strings and display them in a specified format. String formatting is powerful and flexible to meet a variety of needs. Whether it is simple splicing or complex data display, Golang provides a wealth of formatting options, allowing us to easily process strings. Next, we will introduce you to the string formatting usage and common techniques in Golang in detail.

Question content

I have the following code,

04f9a41e7ad1276acdd8aa486b779​​d7c

The output is,

0, 0, []int, true, []int(nil)

I'm really confused about the usage of "%[3]v",..because I'm only passing 4 parameters...

My desired output is

0, 0, []int, true

But the "[]int(nil)" in the output confuses me a bit.

Solution

You can view the fmt package documentation:

So in your specific example, using %#[3]v you will again print the third argument in the default format %v to get a zero slice[]int(nil).

The above is the detailed content of Golang string formatting. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete