I created an winforms application
, which creates a small SQLite database
for every user. The database name
contains the e-mailaddress
of the user.
Scenario:
a user with e-mailaddress: test@test.com
uses the application, the following database
will be created:
test@test.com.sqlite
I know that there are scenario's that the e-mailaddress converted to a path, will not be converted to a valid path.
the following characters are reserved by path: / \ ? % * : | " < > . and a space
I'm currently using the next method to filter the e-mailaddress:
public string ReturnFilteredUsername(string username)
{
username = username.Replace("<", "x"); username = username.Replace(">", "x"); username = username.Replace(":", "x"); username = username.Replace("\"", "x");
username = username.Replace("/", "x"); username = username.Replace(@"\", "x"); username = username.Replace("|", "x"); username = username.Replace("?", "x");
username = username.Replace("*", "x");
return username;
}
All reserved characters get replaced by an "x" at the moment, I want to convert all invalid characters to "%20". It is possible for me to just replace the "x" with "%20", but I don't think that's a 'clean' method
Can somebody come up with a more 'clean' method?
Thanks in advance!