Próbuję tłumaczyć następujące slugify metodę z PHP do C#: http://snipplr.com/view/22741/slugify-a-string-in-php/Slugify i Transliteracja znaków w języku C#
Edit: Dla wygody, tutaj kod z góry:
/**
* Modifies a string to remove al non ASCII characters and spaces.
*/
static public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
if (function_exists('iconv'))
{
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
}
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text))
{
return 'n-a';
}
return $text;
}
mam nie probleming kodowania resztę z wyjątkiem nie mogę znaleźć C# odpowiednik następującej linii kodu PHP:
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
Edit: Cel ten jest przełożenie znaków spoza ASCII, takie jak Reformáció Genfi Emlékműve Előtt
do reformacio-genfi-emlekmuve-elott
Czy myślisz o opublikowaniu gotowego rozwiązania, więc mógłbym rzucić okiem? – chakrit