Go 語言提供內置支持,以通過 strconv 包實現與基本數據類型的字符串表示之間的轉換。這個包提供了一個 IsPrint() 函數,用於檢查符文是否被 Go 定義為可打印與 unicode.IsPrint 相同的定義,包括字母、數字、標點符號、符號和 ASCII 空間。要訪問 IsPrint() 函數,您需要借助 import 關鍵字在程序中導入 strconv 包。
用法:
func IsPrint(x rune) bool
參數:此函數采用符文類型的一個參數,即 x。
返回值:如果 Unicode 將符文定義為圖形,則此函數返回 true。否則,返回false。
範例1:
// Golang program to illustrate
// strconv.IsPrint() Function
package main
import (
"fmt"
"strconv"
)
func main() {
// Checking whether the rune
// is defined as printable by Go
// Using IsPrint() function
fmt.Println(strconv.IsPrint('?'))
fmt.Println(strconv.IsPrint('b'))
}
輸出:
true true
範例2:
// Golang program to illustrate
// strconv.IsPrint() Function
package main
import (
"fmt"
"strconv"
)
func main() {
// Checking whether the rune
// is defined as printable by Go
// Using IsPrint() function
val1:= 'a'
res1:= strconv.IsPrint(val1)
fmt.Printf("Result 1:%v", res1)
val2:= '?'
res2:= strconv.IsPrint(val2)
fmt.Printf("\nResult 2:%v", res2)
val3:= '\001'
res3:= strconv.IsPrint(val3)
fmt.Printf("\nResult 3:%v", res3)
}
輸出:
Result 1:true Result 2:true Result 3:false
相關用法
- Golang strconv.QuoteRune()用法及代碼示例
- Golang strconv.Quote()用法及代碼示例
- Golang strconv.QuoteRuneToGraphic()用法及代碼示例
- Golang strconv.FormatBool()用法及代碼示例
- Golang strconv.CanBackquote()用法及代碼示例
- Golang strconv.FormatUint()用法及代碼示例
- Golang strconv.IsGraphic()用法及代碼示例
- Golang strconv.Itoa()用法及代碼示例
- Golang strconv.QuoteToGraphic()用法及代碼示例
- Golang strconv.QuoteRuneToASCII()用法及代碼示例
- Golang strconv.QuoteToASCII()用法及代碼示例
- Golang math.Lgamma()用法及代碼示例
- Golang math.Float64bits()用法及代碼示例
- Golang atomic.AddInt64()用法及代碼示例
- Golang atomic.StoreInt64()用法及代碼示例
- Golang reflect.FieldByIndex()用法及代碼示例
- Golang string.Contains用法及代碼示例
- Golang bits.Sub()用法及代碼示例
- Golang io.PipeWriter.CloseWithError()用法及代碼示例
注:本文由純淨天空篩選整理自ankita_saini大神的英文原創作品 How to use strconv.IsPrint() Function in Golang?。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。