Closed jeromyanglim closed 12 years ago
One simple strategy:
gsub('[^a-zA-Z]', '', x)
This will remove any characters in x
that are not lower or upper case letters between a and Z.
gsub
stands for global substitution (i.e., not just the first occurrence of a match'[^a-zA-Z]'
This is pattern that matches any characters not (carat ^
is the not
operator) in the specified ranges ie., lower case letters (a-z
) and upper case letters (A-Z
).''
Limitations: a broader range of characters are permitted in file names, and this does not deal with long strings.
I have a database with participant names and I want to use the participant name to generate file names. However, there are few names like "A/Prof" where illegal characters for file names appear. How can I cleanse these raw names.