Skip to content

Instantly share code, notes, and snippets.

@vkbandi
Created September 16, 2015 20:27
Show Gist options
  • Save vkbandi/4442c9cc2e60d2edd04c to your computer and use it in GitHub Desktop.
Save vkbandi/4442c9cc2e60d2edd04c to your computer and use it in GitHub Desktop.
C# simple class to convert a URL into acceptable windows file name
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Coderbuddy
{
public class FileNameFromURL
{
public string ConvertToWindowsFileName(string urlText)
{
List<string> urlParts = new List<string>();
string rt = "";
Regex r = new Regex(@"[a-z]+", RegexOptions.IgnoreCase);
foreach (Match m in r.Matches(urlText))
{
urlParts.Add(m.Value);
}
for (int i = 0; i < urlParts.Count; i++)
{
rt = rt + urlParts[i];
rt = rt + "_";
}
return rt;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment