gpt4 book ai didi

javascript - 如何获取字符的Unicode属性?

转载 作者:行者123 更新时间:2023-11-28 11:00:37 25 4
gpt4 key购买 nike

在 Python 中,我使用 unicodedata 包来识别字符串开头的标点符号:

import unicodedata as UD

_string = '¿para qué?'
if UD.category(_string[0]).startswith('P'):
print('Punctuation at beginning of string.')

有没有办法在 JavaScript 中做到这一点?

最佳答案

似乎没有内置方法来获取此信息。

粗略搜索显示,它的一个流行软件包是 unicode-properties ,其构建脚本使用名为 codepoints 的包编译 JSON 数据库。 .

代码点包包含几个大文本文件,这些文件似乎来自 Unicode 字符数据库 https://unicode.org/ucd/ .

由此我可以得出结论,在 JS 中获取信息的唯一方法是通过这个外部源。

关于javascript - 如何获取字符的Unicode属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55594852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com