I have been trying to make a method that does a "string cleaning process" and wanted to use it like one would use a simple string.Trim() or string.Normalize().
Method
public string ToFriendlyDOSNameString(string input)
{
Regex whitespaces = new Regex(".*?([ ]{2,})");
input = input.Normalize().Replace("\\", " ").Replace("/", " ").Replace("\"", " ")
.Replace("*", " ").Replace(":", " ").Replace("?", " ")
.Replace("<", " ").Replace(">", " ").Replace("|", " ")
.Replace("!", " ").Replace(".", " ").Replace("'", " ").Trim();
string clone = input;
foreach (Match match in whitespaces.Matches(input))
{
clone = clone.Replace(match.Groups[1].Value, " ");
}
input = clone;
return input;
}
And what I am looking for is a way to use this method in the following manner:
string example = "Some Random Text";
example = example.ToFriendlyDOSNameString();
For reference, I'm currently using this on a console application and this method is placed right under the "main method", I don't exactly know where I'd place a method for it to have the behavior I want it to have...