0

Link to R-Faq Duplicate (different from above)

I have a string as follows:

 "[{\"Year\":\"\",\"Market\":\"The Place\",\"Due\":\"\"}]"

And I need to remove the backslashes to have:

"[{"Year":"","Market":"The Place","Due":""}]"

I have tried:

stri_unescape_unicode(theString)

and also:

gsub("\\","",theString)

But neither works.

Community
  • 1
  • 1
Cybernetic
  • 12,628
  • 16
  • 93
  • 132
  • 1
    How it prints is not what it is. Try writing `theString` to a file, or calling `cat(theString, "\n")`. – Joshua Ulrich Jan 29 '15 at 21:52
  • Interesting. So when I do cat(theString) is looks perfect. So this is actually what is there? – Cybernetic Jan 29 '15 at 21:53
  • 2
    Didn't someone ask this yesterday? It might be worth working up a nice definitive explanation and giving it an [tag:r-faq] tag. – Gregor Thomas Jan 29 '15 at 21:57
  • none of those approaches are working in this case. – Cybernetic Jan 29 '15 at 22:05
  • The first line of that answer is very relevant: "There is no backslash in that string. The displayed backslash is an escape marker." This is demonstrated by Josh Ulrich's comment. – Gregor Thomas Jan 29 '15 at 23:38
  • The danger in using `cat` to demonstrate the non-existence of the back-slash was demonstrated by the other questioner then trying to use the result of the `cat`-call and finding that it is NULL. (But getting a rather cryptic error message for his trouble.) Better I advise would be to use `print(theString, quote=FALSE)` – IRTFM Jan 30 '15 at 00:06
  • 2
    @Gregor: Do you prefer the linked-to answer or the one I gave yesterday to a somewhat similar question: http://stackoverflow.com/questions/28204507/remove-backslashes-with-quotes/28204611#28204611 ? I think yesterday's answer was more complete. – IRTFM Jan 30 '15 at 00:17
  • @BondedDust Much prefer yours! I just added the [r-faq] tag and tried to make the title a little more general. – Gregor Thomas Jan 30 '15 at 05:34

0 Answers0