I’m looking for a C# snippet to remove and store any punctuation from the end of a string only.
Example:
- Test! would return !
- Test;; would return ;;
-
Test?:? would return ?:?
-
!!Test!?! would return !?!
I have a rather clunky solution at the moment but wondered if anybody could suggest a more succinct way to do this.
My puncutation list is
new char[] { '.', ':', '-', '!', '?', ',', ';' })
Using Linq:
The HashSet is not mandatory, you can use Linq’s Contains on the array directly.