如何在Common Lisp中删除字符串中的转义双引号?

ˆᵛˆ*_*ˆᵛˆ 0 string common-lisp

跑步(cl-json:encode-json-to-string 'ctx)"\"ctx\""

我需要的"ctx"不是"\"ctx\"".

我可以使用cl-ppcre并删除字符串中匹配的双引号.然而,这似乎有点矫枉过正.有没有其他方法可以做到这一点?

Rai*_*wig 5

什么gives "\"ctx\""意思?

Common Lisp \在打印结果中使用转义字符作为转义字符.

字符串本身有五个字符:

CL-USER 12 > (describe "\"ctx\"")

"\"ctx\"" is a SIMPLE-BASE-STRING
0      #\"
1      #\c
2      #\t
3      #\x
4      #\"
Run Code Online (Sandbox Code Playgroud)

您可以打印字符串内容:

CL-USER 11 > (write-string "\"ctx\"")
"ctx"
"\"ctx\""
Run Code Online (Sandbox Code Playgroud)

您还可以删除第一个和最后一个字符:

CL-USER 10 > (subseq "\"ctx\"" 1 (- 6 2))
"ctx"
Run Code Online (Sandbox Code Playgroud)

您还可以修剪周围的所有"字符:

CL-USER 13 > (string-trim "\"" "\"ctx\"")
"ctx"

CL-USER 14 > (string-trim '(#\") "\"ctx\"")
"ctx"
Run Code Online (Sandbox Code Playgroud)

字符串修剪将一系列字符作为第一个参数:要删除的字符.第二个参数是字符串.

请注意,它将从正面和背面删除所有此类字符:

CL-USER 15 > (string-trim "\"" "\"\"\"\"ctx\"\"\"\"\"\"\"")
"ctx"
Run Code Online (Sandbox Code Playgroud)