相关疑难解决方法(0)

C#中的Slugify和字符音译

我正在尝试将以下slugify方法从PHP转换为C#:http://snipplr.com/view/22741/slugify-a-string-in-php/

编辑:为方便起见,这里是上面的代码:

/**
 * 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;
}
Run Code Online (Sandbox Code Playgroud)

除了我找不到以下PHP代码行的C#等价物之外,我没有遇到任何问题.

$text = …
Run Code Online (Sandbox Code Playgroud)

c# transliteration internationalization slug

12
推荐指数
2
解决办法
7574
查看次数

标签 统计

c# ×1

internationalization ×1

slug ×1

transliteration ×1