国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

我將此方法移植到VB.NET上了,請看源碼(二)

2024-07-10 13:12:58
字體:
來源:轉載
供稿:網友
#region "由拼音到拼音"
    public shared function getpytopy(byval pystr as string, _
                                     optional byval iscomp as boolean = false) as string
        if pystr.length = 0 then exit function

        miscompelled = iscomp

        dim tonesite as integer
        dim tonevalue as integer
        dim tonechar as char

        tonesite = gettonesite(pystr)
        if tonesite = -1 then
            return pystr
        elseif tonesite < -1 then
            exit function
        end if

        tonevalue = gettonevalue(pystr, tonesite)
        if tonevalue = -1 then exit function

        if miscompelled then
            tonechar = gettonechar(pystr, tonesite - 1)
        else
            tonechar = gettonechar(pystr)
        end if
        if not ispychar(tonechar) then exit function
        return conversion(pystr, tonesite, tonevalue, tonechar)

    end function
    '返回標明聲調數值的位置
    private shared function gettonesite(byval pystr as string) as integer
        if pystr.length = 0 then exit function
        dim i as integer, j as integer = 0
        '檢查字串中有幾個數字
        for i = 0 to pystr.length - 1
            if char.isnumber(pystr.chars(i)) then
                j += 1
            end if
        next
        if j = 0 then       '沒有數字,即沒有標明聲調的數值
            return -1
        elseif j = 1 then   '有一個數字,合法
            for i = 0 to pystr.length - 1
                if char.isnumber(pystr.chars(i)) then
                    return i
                end if
            next
        else                '有多個數字,不合法,返回其相反數
            return -j
        end if
    end function
    '返回聲調是幾聲
    private shared function gettonevalue(byval pystr as string, _
                                         byval site as integer) as integer
        if pystr.length = 0 then exit function
        if site >= 0 then
            dim value as char = pystr.chars(site)
            dim num as integer
            if char.isnumber(value) then
                num = ctype(value.tostring, integer)
                if num >= 0 and num <= 4 then
                    return num
                else
                    return -1
                end if
            else
                return -1
            end if
        end if
    end function
    '返回要標聲調的字母
    private shared function gettonechar(byval pystr as string, _
                                     byval site as integer) as char
        if pystr.length = 0 then exit function
        if site >= 0 then
            dim value as char = pystr.chars(site)
            return value
        end if
    end function
    private shared function gettonechar(byval pystr as string) as char
        if pystr.length = 0 then exit function
        dim chr as char

        if pystr.indexof(a(0)) >= 0 then
            chr = pystr.chars(pystr.indexof(a(0)))
        elseif pystr.indexof(o(0)) >= 0 then
            chr = pystr.chars(pystr.indexof(o(0)))
        elseif pystr.indexof(e(0)) >= 0 then
            chr = pystr.chars(pystr.indexof(e(0)))
        elseif pystr.indexof(i(0)) >= 0 then
            chr = pystr.chars(pystr.indexof(i(0)))
        elseif pystr.indexof(u(0)) >= 0 then
            chr = pystr.chars(pystr.indexof(u(0)))
        elseif pystr.indexof(v(0)) >= 0 then
            chr = pystr.chars(pystr.indexof(v(0)))
        end if

        return chr
    end function
    '判斷是否為合法的拼音字符
    private shared function ispychar(byval chr as char) as boolean
        select case chr
            case "a"c
                return true
            case "o"c
                return true
            case "e"c
                return true
            case "i"c
                return true
            case "u"c
                return true
            case "v"c
                return true
            case else
                return false
        end select
    end function
    '轉換
    private shared function conversion(byval pystr as string, _
                                       byval tonesite as integer, _
                                       byval tonevalue as integer, _
                                       byval tonechar as char) as string
        if tonevalue >= 1 and tonevalue <= 4 then
            select case tonechar
                case "a"
                    pystr = pystr.replace(tonechar, a(tonevalue).chars(0))
                case "o"
                    pystr = pystr.replace(tonechar, o(tonevalue).chars(0))
                case "e"
                    pystr = pystr.replace(tonechar, e(tonevalue).chars(0))
                case "i"
                    pystr = pystr.replace(tonechar, i(tonevalue).chars(0))
                case "u"
                    pystr = pystr.replace(tonechar, u(tonevalue).chars(0))
                case "v"
                    pystr = pystr.replace(tonechar, v(tonevalue).chars(0))
            end select
            pystr = pystr.replace(tonevalue.tostring, "")
            return pystr
        end if
    end function
#end region

#region "由漢字到拼音"
    public shared function gethztopy(byval hzstr as string, _
                                 optional byval tonevalue as integer = 0, _
                                 optional byval iscomp as boolean = false) as string
        'byval tonevalue as integer, _
        if hzstr.length = 0 then exit function
        if pylist.count = 0 then loadpychars()
        miscompelled = iscomp
        if miscompelled then
        else
            dim tmpstr as string = ""
            dim i as integer
            dim num as integer
            for i = 1 to hzstr.length
                num = asc(hzstr)
                debug.writeline(num.tostring)
                tmpstr = getpychars(num)
                tmpstr = getpytopy(tmpstr & tonevalue)
                return tmpstr
            next
        end if
    end function

    private shared function getpychars(byval num as integer) as string
        if num > 0 and num < 160 then
            return chr(num)
        else
            if num < -20319 or num > -10247 then
                return ""
            else
                dim i, value as integer
                for i = pylist.count - 1 to 0 step -1
                    if pylist.getbyindex(i) <= num then exit for
                next
                'value = ctype(pylist.getbyindex(i), integer)
                return pylist.getkey(i).tostring
            end if
        end if
    end function
#end region

end class
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 咸阳市| 永福县| 漳平市| 壤塘县| 阳春市| 金堂县| 呈贡县| 娱乐| 天峻县| 洛宁县| 溧水县| 柞水县| 丽江市| 北票市| 舞阳县| 尤溪县| 精河县| 贵港市| 潜江市| 根河市| 逊克县| 莆田市| 临清市| 秦安县| 南陵县| 玉林市| 洛扎县| 黑水县| 辉南县| 永安市| 大洼县| 禹城市| 阿尔山市| 阜阳市| 黄浦区| 隆昌县| 嘉峪关市| 竹溪县| 泾川县| 尖扎县| 太仓市|