Trim curly braces from string
Asked Answered
S

1

2

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?

Splutter answered 29/12, 2013 at 15:58 Comment(0)
H
4
CL-USER 13 > (string-trim '(#\{ #\}) "{1991-05-13}")
"1991-05-13"

CL-USER 14 > (string-trim "{}" "{1991-05-13}")
"1991-05-13"
Hubris answered 29/12, 2013 at 16:11 Comment(2)
Alternatively, (string-trim "{}" "{1991-05-13}") (the character-bag can be any sequence and it may be more natural to express it as a string).Justify
@Vatine: that's a very useful remark. Thanks! I've added it as example.Hubris

© 2022 - 2024 — McMap. All rights reserved.