-2

I have a string 'ABC1\001ABCEFCGJS' I want to extract only 001ABCEFCGJS from this string How to do so in R? My String will be a dynamic string. So the solution should be such that function can read anything after backslash.

Arpit Gupta
  • 125
  • 1
  • 1
  • 9

1 Answers1

2

One option would be to convert to raw and then remove the elements, while appending the correct raw value for '001'

rawToChar(c(charToRaw('001'),charToRaw(str1)[-(1:5)]))
#[1] "001ABCEFCGJS"

data

str1 <- 'ABC1\001ABCEFCGJS' 
akrun
  • 874,273
  • 37
  • 540
  • 662
  • Thanks for this reply,but my string will be a dynamic one. So my purpose is to extract anything in a string after the backslash. – Arpit Gupta Dec 11 '19 at 05:37