拆分控件的语法



我已经从。net Core移植了一个应用程序到。net Framework,它似乎对一切都很好,除了一行,我必须分割一个字符串,以便用它填充一个表。然后我要擦掉除一个空格外的所有空格所以我写:

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:UsersNicolasourcereposFDS2AnsysFDS2AnsysForm2.vb   113 Active

我认为我必须将空格" "c表示为字符,但我不明白如何表示。有人能帮我解决这个问题吗?非常感谢,所有人都会回答我。致以最亲切的问候。

由于Split期望字符数组或字符串数组作为第一个参数,您应该更改您的代码如下:

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

最新更新