5
I need to create a folder on the file server and realized that the variable that receives one of the information is coming with invalid characters ( / : * ? " < > |) for creating a folder on Windows.
string Caminho = Path.Combine(PastaPadrao,txtInfoUser.Text);
In the case of character (:), it is relevant to the user and therefore needs to be recorded, but nothing prevents me from making a Replace()
for underline, but painted the doubt: What is the correct way to do the Replace()
in that case?
return Caminho.Replace(@"\", "_")
.Replace(@"/", "_")
.Replace(@":", "_")
.Replace(@"*", "_")
.Replace(@"?", "_")
.Replace(@"""", "_")
.Replace(@"<", "_")
.Replace(@">", "_")
.Replace(@"|", "_");
If I do it this way, 9 different instances of the string?
For now, I did it this way:
StringBuilder CaminhoSemCaracteresInvalidos = new StringBuilder(Caminho);
CaminhoSemCaracteresInvalidos.Replace(@"\", "_")
.Replace(@"/", "_")
.Replace(@":", "_")
.Replace(@"*", "_")
.Replace(@"?", "_")
.Replace(@"""", "_")
.Replace(@"<", "_")
.Replace(@">", "_")
.Replace(@"|", "_");
return CaminhoSemCaracteresInvalidos.ToString();
My concern is to try to do the best way so that the application does not suffer at the end of the day, always trying to do what is right from the point of view of performance and good practice, but I also don’t know if I’m mounting an atomic bomb to kill a fly.
This last paragraph of yours sums up my stance on the final outcome. Today with 10 users and 5 folders works well, but what about tomorrow when my application grows? She might not even grow up, stay with 10 users her whole life, but what? Take a chance? I still have a lot of beans and flour to eat, but the basics I feel I have to do...
– Eduardo Oliveira