Created
September 16, 2015 20:27
-
-
Save vkbandi/4442c9cc2e60d2edd04c to your computer and use it in GitHub Desktop.
C# simple class to convert a URL into acceptable windows file name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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