在 Prolog 中获取字符串的最后一个字符 [英] Getting last char of a string in Prolog

查看:88
本文介绍了在 Prolog 中获取字符串的最后一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取字符串的最后一个字符.例如:

I need to get the last char of a string. For example:

?- last_char('abde', X).
X = 'e'

?- last_char('abdef', X).
X = 'f'

有人可以帮我吗?我是 Prolog 的新手.

Could someone help me, please? I'm new to Prolog.

推荐答案

sub_atom/5,一个非常方便的 ISO 内置:

with a little help from sub_atom/5, a really handy ISO builtin:

?- sub_atom(abdef, _, 1, 0, C).
C = f.

这篇关于在 Prolog 中获取字符串的最后一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆