SWI Prolog 转义引号 [英] SWI Prolog escape quotes

查看:31
本文介绍了SWI Prolog 转义引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在序言中将"放在一个字符串周围.我从另一个程序获得输入,看起来我无法在这个程序中转义 ",所以我必须在 prolog 中添加 " 否则 prolog 语句不起作用.

I need to put " " around a String in prolog. I get the input from another program and as it looks I can't escape the " in this program, so i have to add the " in prolog otherwise the prolog statement doesn't work.

感谢您的帮助!

推荐答案

有关 字符串 的讨论,请参见此处,它们是 SWI-Prolog 特定的,但使用与原子相同的转义规则.有很多方法可以在 Prolog 文本的原子中输入引号:

For a discussion of strings see here, they are SWI-Prolog specific but use the same escape rules as atoms. There are many ways to enter quotes into an atom in a Prolog text:

1) 将它们加倍.例如,'can'''t be' 是一个原子,用单引号作为第四个字符,没有其他字符单引号.

1) Doubling them. So for example 'can''t be' is an atom, with a single quote as the fourth character, and no other single quotes in it.

2) 使用反斜杠转义它们.所以例如'can\'t be' 和 'can'''t be 是同一个原子.

2) Escaping them, with the backslash. So for example 'can\'t be' is the same atom as 'can''t be'.

3) 字符编码,使用八进制代码和结束反斜杠.例如,'can\47\t be' 与 'can'''t be' 是同一个原子.

3) Character coding them, using octal code and a closing back slash. So for example 'can\47\t be' is the same atom as 'can''t be'.

4) 字符编码,使用十六进制代码和结束反斜杠.例如,'can\x27\t be' 和 'can'''t be' 是同一个原子.

4) Character coding them, using hex code and a closing back slash. So for example 'can\x27\t be' is the same atom as 'can''t be'.

以上可能性都是在ISO标准中定义的.一种Prolog 的实现可能会定义更多的可能性.

The above possibilities are all defined in the ISO standard. A Prolog implementation might define further possibilities.

再见

P.S.:这是在 SWI-Prolog 中运行的示例,使用不同的示例字符.在下面的第一个示例查询中,您不需要需要加倍,加倍只能对周围的报价进行.

P.S.: Here is an example run in SWI-Prolog, using a different example character. In the first example query below, you don't need doubling, doubling can only be done for the surrounding quote.

下面的最后一个示例查询显示了 SWI-Prolog 特定的语法在 ISO 标准中找不到,即使用反斜杠u 具有固定宽度的十六进制代码:

The last example query below shows a SWI-Prolog specific syntax which is not found in the ISO standard, namely using a backslash u with a fixed width hex code:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.33)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam

?- X = 'she said "bye"'.
X = 'she said "bye"'.

?- X = 'she said \"bye\"'.
X = 'she said "bye"'.

?- X = 'she said \42\bye\42\'.
X = 'she said "bye"'.

?- X = 'she said \x22\bye\x22\'.
X = 'she said "bye"'.

?- X = 'she said \u0022bye\u0022'.
X = 'she said "bye"'.

这篇关于SWI Prolog 转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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