Ali
Ali

Reputation: 43

How to replace specific characters in a string in Clojure?

I'm trying to replace all single quotation marks with double quotation marks in Clojure. i.e. if the string id " 'name' " I want it to become " "name" ". How can I do that?

I've been trying to use the replace function like this:

(clojure.string/replace " 'The color is red' " #"'" """)

but it is not working.

Upvotes: 0

Views: 348

Answers (2)

Alan Thompson
Alan Thompson

Reputation: 29958

I do this so often I made some convenience functions:

You can find the details here. You may also find this template project useful, esp. the documentation list at the end.

Upvotes: 1

akond
akond

Reputation: 16035

You've forgotten to escape the double quotation mark

(clojure.string/replace " 'The color is red' " #"'" "\"")

Upvotes: 2

Related Questions