'string'类型的值不能转换为'1维数组字符串' [英] value of type 'string' cannot be converted to '1-dimensional array of string'

查看:254
本文介绍了'string'类型的值不能转换为'1维数组字符串'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始问题就在这一行......

The original issue is on this line...

Dim currentAuthorarr() As String = m_favoriteAddressees.Item(intadd).FullName.Split(CChar(" "))

使用全名,它使用Split函数读取第一个空格字符并认为这是名字和姓氏的分隔符。

Using the full name, it uses the Split function that reads the first space character and thinks this is the delimiter of the first name and surname.

但是如果fullname包含姓氏前缀,则只读取firstname和prefix,并忽略姓氏。当正确的行为是"Michael do Flavor"时显示'Michael do'

However if the fullname contains a surname prefix it only reads the firstname and prefix, and ignores the surname. Displaying 'Michael do' when the correct behaviour is 'Michael do Flavour'

由于全名实际上在列表框中正确显示,因此不需要拆分

The split isn’t required as the fullname actually displays correctly in the listbox

如果我将行更改为 

If I change the line to 

Dim currentAuthorarr As String() = m_favoriteAddressees.Item(intadd).FullName




代码错误显示'string'的值无法转换为'1维数组字符串'

The code error displays value of 'string' cannot be converted to '1-dimensional array of string'

以下代码

任何想法

TIA

Public Overridable ReadOnly Property SelectecAddressee() As Addressee
            Get
                If cbFavoriteAddressees.SelectedItem Is Nothing Then
                    Return Nothing
                End If

                Dim currentAddressee As Addressee = Nothing

                If binternalmemo = True Then
                    For intadd = 0 To m_favoriteAddressees.Count - 1


                        ' Dim currentAuthorarr() As String = m_favoriteAddressees.Item(intadd).FullName.Split(CChar(" "))


                        Dim currentAuthorarr As String() = m_favoriteAddressees.Item(intadd).FullName

                        Dim currentAuthor As String = currentAuthorarr.GetValue(1).ToString & " " & Replace(currentAuthorarr.GetValue(0).ToString, ",", "")
                        'MsgBox(m_favoriteAddressees.Item(intadd).FullName & " = " & cbFavoriteAddressees.SelectedItem.ToString)
                        If m_favoriteAddressees.Item(intadd).FullName & " (" & m_favoriteAddressees.Item(intadd).Company & ")" = cbFavoriteAddressees.SelectedItem.ToString Then
                            currentAddressee = CType(m_favoriteAddressees.Item(intadd), Addressee)
                        End If
                    Next
                Else
                    currentAddressee = CType(cbFavoriteAddressees.SelectedItem, Addressee)

                End If







推荐答案

您好

这有什么帮助吗?

        Dim s As String = "Michael do Flavour"
        Dim a() As String = Split(s, " "c)
        ' at this point,
        ' a(0) = "Michael"
        ' a(1) = "do"
        ' a(2) - "Flavour"

        s = "This is a longer string"
        a = Split(s, " "c)
        ' at this point,
        ' a(0) = "This"
        ' a(1) = "is"
        ' a(2) - "a"
        ' a(1) = "longer"
        ' a(2) - "string"


这篇关于'string'类型的值不能转换为'1维数组字符串'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆