-4

How do I remove an interpunct (aka interpoint, middle dot, middot) from a string? I am looking for something like trimws, but trimws doesn't work on the interpunct. Cheers

nm200
  • 336
  • 2
  • 15
  • 2
    Can you give a [minimal, reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and the code that is not working for you? – markus Sep 25 '18 at 09:03

1 Answers1

1

I believe this is what you're looking for.

string <- c("· interpunct", "interpunct · interpunct", "interpunct · ")
#[1] "· interpunct"            "interpunct · interpunct" "interpunct · " 

sub("(?:\\s?)+·(?:\\s?)+", "", string)
#[1] "interpunct"           "interpunctinterpunct" "interpunct"  
Andre Elrico
  • 10,956
  • 6
  • 50
  • 69
  • Thanks, that works for what you have written, but unfortunately not for my string. In my string, the interpunct looks like a space (not the symbol you write), but isn't removed with trimws. When I copy and paste the string into word, it gives me the interpunct symbol. The string came from a confidential document, so unfortunately I can't upload it here. Any idea how to identify and remove it? – nm200 Sep 25 '18 at 10:02
  • Change the content of your confidential string to make it non-confidential by keeping the same "structure". Otherwise, we have to play the guessing game. – Andre Elrico Sep 25 '18 at 10:06
  • You probably just want to copy "that strange interpunct" character of yours and replace it with my interpunct character in the regex. – Andre Elrico Sep 25 '18 at 10:10
  • Hi Andre, thanks for the help. When I copy and paste the character in R, it comes out as a white space. That means that I can't paste here an example, and copy and paste into the regex doesn't work either. The only time I have been able to see a difference, is when I copy and paste into word. Then I see the intepunct character. I don't know how I can copy the symbol here so that it appears correctly. – nm200 Sep 25 '18 at 10:22