Azra
Bronze Üye
-
- Katılım
- 11 Mart 2014
-
- Mesajlar
- 3.834
-
- Tepkime puanı
- 13
-
- ForumSAL Yaşı:
- 12 yıl 7 ay
- Kıdem:
- Forumun Eskisi
-
- Yaş
- 35
Metindeki özel karakterleri çıkararak güvenli şekilde dosya ve klasör adı üreten fonksiyon (Metinden dosya adı üretme = metinden-dosya-adi-uretme)
Kod:
public static string FilenameFromTitle(string name)
{
string safe = name.Trim();
safe = safe.Replace(" ", "-").ToLower();
if(safe.IndexOf("--") > -1)
while(safe.IndexOf("--") > -1)
safe = safe.Replace("--", "-");
safe = Regex.Replace(safe, "[^a-z0-9\\-]", "");
if(safe.Length > 50)
safe = safe.Substring(0, 49);
// clean the beginning and end of the filename
char[] replace = {'-','.'};
safe = safe.TrimStart(replace);
safe = safe.TrimEnd(replace);
return safe;
}