如何操作序言中的字符串? [英] How to manipulate strings in prolog?
本文介绍了如何操作序言中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的基地里有这个事实事实(姓名",姓氏",123").如果我简单地写下这个问题:事实(X,_,_).对于 X 我得到一些不明的输出.如何检索任何这些值,或如何获得此输出??-事实(X,_,_).输出:名称.
I have this fact in my base fact("name","surname","123"). if i simply write this question: fact(X,_,_). For X I get some unidentified output. How can I retrieve any of this values, or how to get this output? ?-fact(X,_,_). output: name.
先谢谢了.
推荐答案
在 SWI-Prolog 中你可以使用 string_to_atom/2
:
In SWI-Prolog you can use string_to_atom/2
:
?- assert(fact("name", "surname", "123")).
true.
?- fact(Tmp, _, _), string_to_atom(Tmp, X).
Tmp = [110, 97, 109, 101],
X = name.
这篇关于如何操作序言中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文