ChaoYang0502
ChaoYang0502
采纳率100%
2015-12-29 02:16

注释一段PHP代码,能翻译成C#最好

10
已采纳
 function pinyin($s, $isfirst = false) {
    static $pinyins;

    $s = trim($s);
    $len = strlen($s);
    if($len < 3) return $s;

    if(!isset($pinyins)) {
        $data = '一:yi|丁:ding|丂:kao|七:qi|丄:shang|丅:xia|丆:mu|万:wan|丈:zhang|三:san|上:shang|下:xia|丌:ji|不:bu|与:yu|丏:mian|丐:gai|丑:chou|丒:chou|专:zhuan|且:qie|丕:pi|世:shi|丗:shi|丘:qiu|丙:bing|业:ye|丛:cong|东:dong|丝:si|丞:cheng|丟:diu|丠:qiu|両:liang|丢:diu|丣:you|两:liang|严:yan|並:bing|丧:sang|丨:gun|丩:jiu|个:ge|丫:ya|丬:zhuang|中:zhong|丮:ji|丯:jie|丰:feng|丱:guan|串:chuan|丳:chan|临:lin|丵:zhuo|丶:zhu|丷:ha|丸:wan|丹:dan|为:wei|主:zhu|丼:jing|丽:li|举:ju|丿:pie|乀:fu|乁:yi|乂:yi|乃:nai|乄:wu|久:jiu|乆:jiu|乇:tuo|么:me|义:yi|乊:ho|之:zhi|乌:wu|乍:zha|乎:hu|乏:fa|乐:le|乑:yin|乒:ping|乓:pang|乔:qiao|乕:hu|乖:guai|乗:cheng';
        $a1 = explode('|', $data);
        $pinyins = array();
        foreach($a1 as $v) {
            $a2 = explode(':', $v);
            $pinyins[$a2[0]] = $a2[1];
        }
    }

    $rs = '';
    for($i = 0; $i < $len; $i++) {
        $o = ord($s[$i]);
        if($o < 0x80) {
            if(($o >= 48 && $o <= 57) || ($o >= 97 && $o <= 122)) {
                $rs .= $s[$i]; // 0-9 a-z
            }elseif($o >= 65 && $o <= 90) {
                $rs .= strtolower($s[$i]); // A-Z
            }else{
                $rs .= '_';
            }
        }else{
            $z = $s[$i].$s[++$i].$s[++$i];
            if(isset($pinyins[$z])) {
                $rs .= $isfirst ? $pinyins[$z][0] : $pinyins[$z];
            }else{
                $rs .= '_';
            }
        }
    }
    return $rs;
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

相关推荐