Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 函数将西里尔文转换为拉丁文_Vb.net_Replace_Converter_Cyrillic_Latin - Fatal编程技术网

Vb.net 函数将西里尔文转换为拉丁文

Vb.net 函数将西里尔文转换为拉丁文,vb.net,replace,converter,cyrillic,latin,Vb.net,Replace,Converter,Cyrillic,Latin,我正在尝试在VB.net中创建自定义的将西里尔文转换为拉丁文的文本函数。我从来没有尝试过自定义函数,所以我不知道我做错了什么。我有一个问题,而且函数不起作用:对象引用未设置为对象的实例 Public Function ConvertCtoL(ByVal ctol As String) As String ctol = Replace(ctol, "Б", "B") ctol = Replace(ctol, "б", "b") **End Function** ' d

我正在尝试在VB.net中创建自定义的将西里尔文转换为拉丁文的文本函数。我从来没有尝试过自定义函数,所以我不知道我做错了什么。我有一个问题,而且函数不起作用:对象引用未设置为对象的实例

    Public Function ConvertCtoL(ByVal ctol As String) As String

    ctol = Replace(ctol, "Б", "B") 
    ctol = Replace(ctol, "б", "b")

**End Function** ' doesn't return a value on all code paths

因为我没有找到从西里尔文到拉丁文文本的解决方案,所以我计划创建一个函数来替换从一个字母表到另一个字母表的每个字母。

您需要
返回ctol
来告诉它返回什么值

也许研究“查找表”可以帮助您创建一个更整洁的函数

编辑:的维基百科条目应该是一个好的开始

下面是一个简单的例子:

Imports System.Text

Module Module1

    Function ReverseAlphabet(s As String) As String
        Dim inputTable() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray()
        Dim outputTable() As Char = "ZYXWVUTSRQPONMLKJIHGFEDBCA".ToCharArray()
        Dim sb As New StringBuilder

        For Each c As Char In s
            Dim inputIndex = Array.IndexOf(inputTable, c)
            If inputIndex >= 0 Then
                ' we found it - look up the value to convert it to.
                Dim outputChar = outputTable(inputIndex)
                sb.Append(outputChar)
            Else
                ' we don't know what to do with it, so leave it as is.
                sb.Append(c)
            End If
        Next

        Return sb.ToString()

    End Function

    Sub Main()
        Console.WriteLine(ReverseAlphabet("ABC4")) ' outputs "ZYX4"
        Console.ReadLine()
    End Sub

End Module

谢谢,你能给我一些关于查找表的链接吗,因为我对此一无所知。@user3338345我已经用一个链接和一个简单的例子编辑了我的答案。