2016-07-24 15 views

Antwort

23

die StrConv Paket

docs

strconv.FormatBool(v)

func FormatBool (b bool) string FormatBool gibt "wahr" oder "falsch"
entsprechend dem Wert von b

verwenden
4

können Sieverwendenwie folgt aus:

package main 

import "fmt" 
import "strconv" 

func main() { 
    isExist := true 
    str := strconv.FormatBool(isExist) 
    fmt.Println(str)  //true 
    fmt.Printf("%q\n", str) //"true" 
} 

oder Sie fmt.Sprint wie diese verwenden:

package main 

import "fmt" 

func main() { 
    isExist := true 
    str := fmt.Sprint(isExist) 
    fmt.Println(str)  //true 
    fmt.Printf("%q\n", str) //"true" 
} 

oder schreiben wie strconv.FormatBool:

// FormatBool returns "true" or "false" according to the value of b 
func FormatBool(b bool) string { 
    if b { 
     return "true" 
    } 
    return "false" 
} 
1

Nur fmt.Sprintf("%v", isExist) verwenden, wie Sie es für fast alle Arten .

Verwandte Themen