I am trying to translate the following slugify method from PHP to C #: http://snipplr.com/view/22741/slugify-a-string-in-php/
Edit: For convenience, here is the code above:
/** * 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; }
I had no problem coding the rest, except that I cannot find the C # equivalent of the following line of PHP code:
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
Edit: The purpose of this is to translate non-ASCII characters such as Reformáció Genfi Emlékműve Előtt to reformacio-genfi-emlekmuve-elott
c # internationalization slug transliteration
Trav L Jan 31 '10 at 23:18 2010-01-31 23:18
source share