拆分控件的语法

Syntax of Split control

我已经将一个应用程序从 .NET Core 移植到 .NET Framework,它似乎对所有内容都很好,除了一行我必须拆分一个字符串以便用它填充 table。然后我必须擦除除一个之外的所有 spaces 所以我写道:

Dim item() As String = line.Trim.Split(" "c, StringSplitOptions.RemoveEmptyEntries)

在 NET Core 中没有发现错误。这里我有以下错误:

Error   BC30518 Overload resolution failed because no accessible 'Split' can be called with these arguments:
    'Public Overloads Function Split(ParamArray separator As Char()) As String()': Value of type 'StringSplitOptions' cannot be converted to 'Char'.
    'Public Overloads Function Split(separator As Char(), count As Integer) As String()': Value of type 'Char' cannot be converted to 'Char()'.
    'Public Overloads Function Split(separator As Char(), options As StringSplitOptions) As String()': Value of type 'Char' cannot be converted to 'Char()'.
    'Public Overloads Function Split(separator As String(), options As StringSplitOptions) As String()': Value of type 'Char' cannot be converted to 'String()'.    FDS2Ansys   C:\Users\Nicola\source\repos\FDS2Ansys\FDS2Ansys\Form2.vb   113 Active

我认为我必须将 space " "c 表示为字符,但我不明白如何做。有谁能帮我解决这个问题吗?非常感谢大家会回答我。最好的问候。

由于 Split 需要字符数组或字符串数​​组作为第一个参数,您应该按如下方式更改代码:

Dim item() As String = line.Trim.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)