Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Go format a string

Shulou Source: shulou.com Published: 2022-06-01 02:38:05 09月21日 Update

This article mainly introduces the relevant knowledge of "how to format a string in Go". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "how to format a string in Go" can help you solve the problem.

Format string

In the Go language, use fmt.Sprintf to format strings and assign values to new strings:

Example

Package main

Import (

"fmt"

)

Func main () {

/ /% d represents an integer number,% s represents a string

Var stockcode=123

Var enddate= "2020-12-31"

Var url= "Code=%d&endDate=%s"

Var target_url=fmt.Sprintf (url,stockcode,enddate)

Fmt.Println (target_url)

}

The output is as follows:

What Code=123&endDate=2020-12-31go is suitable for go is the abbreviation of golang, while golang can do server-side development, and golang is very suitable for log processing, data packaging, virtual machine processing, database agent and so on. In the aspect of network programming, it is also widely used in web applications, API applications and other fields.

This is the end of the introduction to "how Go formats strings". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Characters strings formats knowledge applications data industries processing different practical content examples practicality actual numbers databases articles methods aspects logs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS Linux MariaDB Xiaomi