亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Go 中 unicode 中 IsDigit 和 IsNumber 的區別

Go 中 unicode 中 IsDigit 和 IsNumber 的區別

Go
呼喚遠方 2021-08-10 21:09:43
似乎 unicode 包中的 IsDigit 和 IsNumber 的行為沒有不同,至少在我的以下測試代碼中:package mainimport "fmt"import "unicode"func main() {    r := rune('1')    fmt.Println(unicode.IsDigit(r))    fmt.Println(unicode.IsNumber(r))    //true    //true}他們都打印true。我試圖從他們的源代碼中理解。但是,即使從它們的源代碼來看,我仍然不明白它們之間的區別是什么。// IsNumber reports whether the rune is a number (category N).func IsNumber(r rune) bool {    if uint32(r) <= MaxLatin1 {        return properties[uint8(r)]&pN != 0    }    return isExcludingLatin(Number, r)}// IsDigit reports whether the rune is a decimal digit.func IsDigit(r rune) bool {    if r <= MaxLatin1 {        return '0' <= r && r <= '9'    }    return isExcludingLatin(Digit, r)}
查看完整描述

2 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

總類為數字,子類為十進制數字。


統一碼標準


4. 角色屬性


4.5 一般類別


Nd = Number, decimal digit

Nl = Number, letter

No = Number, other

4.6 數值


Numeric_Value 和 Numeric_Type 是表示數字的字符的規范屬性。


十進制數字。


通常理解的十進制數字是用于形成十進制基數的數字。


例如,


“數字,十進制數字”類別中的 Unicode 字符 (Nd)


“數字、字母”類別 (Nl) 中的 Unicode 字符


“數字、其他”類別中的 Unicode 字符(否)


package main


import (

    "fmt"

    "unicode"

)


func main() {

    digit := rune('1')

    fmt.Println(unicode.IsDigit(digit))

    fmt.Println(unicode.IsNumber(digit))

    letter := rune('Ⅷ')

    fmt.Println(unicode.IsDigit(letter))

    fmt.Println(unicode.IsNumber(letter))

    other := rune('?')

    fmt.Println(unicode.IsDigit(other))

    fmt.Println(unicode.IsNumber(other))

}

輸出:


true

true

false

true

false

true


查看完整回答
反對 回復 2021-08-10
?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

據我所知IsDigit()是一個子集,IsNumber()所以你得到的結果很好,因為兩者都應該評估為true. 的IsNumber是使用以確定它是否是任何數值Unicode類別和IsDigit()檢查它是否是一個基數為10位數..


查看完整回答
反對 回復 2021-08-10
  • 2 回答
  • 0 關注
  • 1035 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號