I am new at C#. I want to write a programme for changing files’ and directories’ names.
public static string ToUrlSlug(this string text)
{
return Regex.Replace(
Regex.Replace(
Regex.Replace(
text.Trim().ToLower()
.Replace("ö", "o")
.Replace("ç", "c")
.Replace("ş", "s")
.Replace("ı", "i")
.Replace("ğ", "g")
.Replace("ü", "u"),
@"\s+", " "), //multiple spaces to one space
@"\s", "-"), //spaces to hypens
@"[^a-z0-9\s-]", ""); //removing invalid chars
}
I want to work on path C:\Users\dell\Desktop\abc.
How can I add this path to my programme?
There are many special cases you should handle to encode a file name as URL, couldn’t you use HttpServerUtility.UrlEncode()?
I’m not sure this is what you want anyway: