In R, if you want to trim all whitespace characters from the end of a string, you'd do trimws(to.be.trimmed, "right"), like so:
> trimws("nauris ", "right")
[1] "nauris"
What if instead of trimming out whitespace characters, I'd want to trim periods (or some other characters)? In Python, you'd do string.rstrip(char)
. Here's some desired outputs:
> rstrip("nauris", "s")
[1] "nauri"
> rstrip("nauris.", ".")
[1] "nauris"
> rstrip("nauris....", ".")
[1] "nauris"
> rstrip("stack", "c")
[1] "stack"
Giving said period as the last argument does not work as it just returns an empty string:
trimws("nauris.", "right", ".")
[1] ""