1

I have the following string and I need to have this characters without "\" and an extra pair of "". So every element of this string looks like "\"USD:US dollar\"", while I should have "USD:US dollar".

This below is the string.

string = c("\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"TO1:Total (all currencies)\"", "\"TO1:Total (all currencies)\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"", "\"USD:US dollar\"", "\"USD:US dollar\"", 
"\"USD:US dollar\"")

How can I have clean character elements?

1
  • There is not a single \ character in the strings, as far as I can see. Instead you’re seeing " characters, which are shown as escaped, i.e. as \". This doesn’t cause problems when actually handling or displaying the strings, it’s merely shown when the strings are displayed via (implicit) print. Commented Mar 24, 2020 at 19:00

1 Answer 1

1

It is the double quote that is creating the issue. We can use gsub

gsub('"', '', string)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.