Golang string formatting

WBOY
Release: 2024-02-09 11:00:09
forward
705 people have browsed it

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)
Copy after login

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
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!