使用 unicode.isdigit()
给定符文是一个数字,但是我如何找出那是哪个数字?
atoi和parseint来自 strconv
不会解析它。
isDigit在所有这些codepoints 中但是我从中弄清楚了任何东西。许多数字范围以其0数字在0结束的代码点开始,但并非全部,所以我不能只是 char& 0xf
。
我唯一的想法是,是否有一种方法可以访问符文的Unicode名称,或者您是否可以访问属性。每个数字Unicode字符(甚至分数)似乎都具有与之相关的平原ASCII编号作为属性,但我似乎找不到一种访问该信息或名称的方法(例如,所有Unicode数字都以“ Digit Zero”结尾为“ Digit Zero”)。我在标准库外面寻找/建筑物吗?
Other answers mention using unicode.IsDigit()
to check if a given rune is a digit or not, but how do I figure out which digit it is then?
Atoi and ParseInt from strconv
won't parse it.
IsDigit checks a table with all of these codepoints in it, but I can't figure out anything from that. Many of the number ranges start with their 0 digit at a codepoint ending in 0, but not all of them so I can't just char & 0xF
.
My only other thoughts is whether there's a way to either access the unicode name of a rune, or whether you can access properties. Every numeric unicode character (even fractions) seems to have a plain ASCII number associated with it behind the scenes as a property, but I can't seem to find a way to access either that information or the name (all unicode digits have names ending in "DIGIT ZERO" for example) anywhere. Am I looking/building outside of the standard library on this one?
发布评论
评论(1)
使用 runeNames package 软件包以根据名称识别数字。
这不是一个星德库软件包,但它是 golang.org/x/
该软件包的确提到了一个文档似乎为每个字符提供了更多信息,包括指定字符在Pline Ascii中的数字,但是,此软件包仅提供名称。只需查看文档,名称似乎遵循
WhatDigit
函数中所示的模式。Using the runenames package to identify a digit based on the name.
This isn't a stardard library package, but it is part of golang.org/x/
The package does mention a document https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt which seems to have further information for each character, including specifying which digit the character is in plain ASCII, however, this package only provides the name. Just looking through the document, the names seem to follow the pattern as shown in the
whatDigit
function.