Trim curly braces from string

2019-07-17 15:33发布

问题:

I am using a Prolog query in a Common Lisp program to get the date of birth from a knowledge base. The query returns the value formatted as {1991-05-13}, and I assign to this value on dob variable with setq: (setq dob {1991-05-13}). I want to use this date value in a new function which takes string, so I am trying to use write-to-string to convert dob to a string with (setq strdob (write-to-string dob)), but it returns

"{1991-05-13}"

I actually want:

"1991-05-13"

which lacks the curly braces. How could I trim the curly braces from the string?

回答1:

CL-USER 13 > (string-trim '(#\{ #\}) "{1991-05-13}")
"1991-05-13"

CL-USER 14 > (string-trim "{}" "{1991-05-13}")
"1991-05-13"