Sometimes it is required to remove some special characters like carriage return, or new line which can be considered as invalid characters, especially while file processing. This method removes any special characters in the input string which is not included in the allowed special character list.