Go
can be used
fmt.Sprintf
to format the string in the following format:
fmt.Sprintf(Format style, parameter list…)
Format style: in the form of a string, formatting symbols to
%at the beginning%sstring format,%ddecimal integer format.Parameter list: multiple parameters are separated by commas, and the number must correspond to the number in the formatting style one by one, otherwise the runtime will report an error.
2.5.1. Example #
package main
import (
"fmt"
"io"
"os"
)
func main() {
// Format the string in go and assign it to a new string, using fmt.Sprintf
// %S represents a string
var stockcode="000987"
var enddate="2020-12-31"
var url="Code=%s&endDate=%s"
var target_url=fmt.Sprintf(url,stockcode,enddate)
fmt.Println(target_url)
// Another instance,% d represents an integer
const name, age = "Kim", 22
s := fmt.Sprintf("%s is %d years old.\\n", name, age)
io.WriteString(os.Stdout, s) // For simplicity, ignore some errors
}
The output is as follows:
Code=000987&endDate=2020-12-31
Kim is 22 years old.
Go
string formatting symbol:
Format | Description |
|---|---|
%v | Output by the original value of the value |
%+v | Expand the structure field name and value on the basis of%v |
%#v | Output values in Go language syntax format |
%T | Output the types and values of the Go language syntax format |
%% | Output% ontology |
%b | The integer is displayed in binary mode |
%o | Integers are displayed in octal mode |
%d | Integers are displayed in decimal mode |
%x | The integer is displayed in hexadecimal mode |
%X | Integers are displayed in hexadecimal, uppercase letters |
%U | Unicode character |
%f | Floating point number |
%p | Pointer, displayed in hexadecimal mode The output is as follows:
Principles, Technologies, and Methods of Geographic Information Systems 102 In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.
|