ForumKalbi.Com

ForumKalbi.Com (https://www.forumkalbi.com/index.php)
-   Bilgisayar (https://www.forumkalbi.com/forumdisplay.php?f=220)
-   -   C# Metinden dosya ve klasör adı üretme (https://www.forumkalbi.com/showthread.php?t=4655)

Candres 27 Ocak 2024 18:58

C# Metinden dosya ve klasör adı üretme
 
C# Metinden dosya ve klasör adı üretme
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;
}


Forum saati; Türkiye'ye göre ayarlanmış olup, şu an saat: 05:53.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Navbar with Avatar by Motorradforum