Path with illegal characters

Hi,

I have to name the path like the subject of the email. In the subject may be lot of different characters like : :/*⌘ʜᘥȯʝʒʝ͢򢳝ʚ�ō𐏿

I have done some replace string like mail.subject.Replace(“*”,“”) for the most common characters but for the weird ones it is very difficult. Is this possible to check the characters and leave only these that are allowed?

You could use method System.IO.Path.GetInvalidFileNameChars() to get all not valid charactes.
Then use this list to replace those by e.g. “_”.

Cheers

2 Likes

Hi, you can replace unwanded characters by leaving only numbers and digits:

System.Text.RegularExpressions.Regex.Replace(your_String,"[^\p{L}|^\p{N}|^\s]","")

image