序言中是否有字母字符检查?

发布于 2024-08-06 03:05:03 字数 426 浏览 4 评论 0原文

您好,

我可以在序言中使用测试或谓词来验证某个给定字符是否是字母顺序的吗?现在,我正在做的是:

非法字符列表:\n -> 10、空间-> 32、!->33、.->46、、->44、:->58、;->59% % 63->? , 45 -> -, 34->", 39-> %

\+member(Ch,[10, 32, 33, 34, 39, 44, 45, 46, 58, 59, 63 ]), %Checking for line return           (\n),     space, punctuations

这些只是我需要检查的几个字符。进行诸如 letter(Ch) 之类的测试。会节省我大量时间,最重要的是一种更具防御性的方法,

谢谢。

Greetings,

Is there was test or a predicate I can use in prolog to verify that a certain given character is alphabetical? Right now, what I'm doing is:

List of unallawed characters: \n -> 10, space -> 32, !->33, .->46, ,->44, :->58, ;->59%
% 63->? , 45 -> -, 34->", 39-> %

\+member(Ch,[10, 32, 33, 34, 39, 44, 45, 46, 58, 59, 63 ]), %Checking for line return           (\n),     space, punctuations

Those are only a few of the characters I need to check for. having a test such as letter(Ch). would save me a great deal of time, and above all be a way more defensive approach.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木格 2024-08-13 03:05:03

is_alpha/1

还有其他谓词,例如 is_lower/1 等。

is_alpha/1

There are also other predicates such as is_lower/1 etc.

音盲 2024-08-13 03:05:03

在 SWI-Prolog 中,这是通过 char_type/2 完成的因为

% X is either a single-character atom or a character code
alphabetical(X) :- char_type(X, alpha).

SWI-Prolog 还提供 ctypes 库,它提供is_alpha

:- use_module(library(ctypes)).
alphabetical(X) :- is_alpha(X).

In SWI-Prolog, this is done with char_type/2 such as

% X is either a single-character atom or a character code
alphabetical(X) :- char_type(X, alpha).

SWI-Prolog also offers the ctypes library which provides is_alpha, etc.

:- use_module(library(ctypes)).
alphabetical(X) :- is_alpha(X).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文