Link to home
Start Free TrialLog in
Avatar of bryanford
bryanford

asked on

Problem with VS2005 and not 2003

I just upgraded to VS2005 and in one section of an app ive been working on i get a problem.

Code:


    Function GetLegalEmail(ByRef anEmail As String) As String
        'Try to extract the legal part of an email e.g. from reply address and return nothing if there is a problem.
        Dim eMailParts(2) As String
        Dim leftPart As String = ""
        Dim rightPart As String = ""
        Try
            GetLegalEmail = ""
            eMailParts = anEmail.Split("@", 2)
            leftPart = getLegalFromRight(eMailParts(0))
            If leftPart = "" Then Exit Function
            rightPart = getLegalFromLeft(eMailParts(1))
            If rightPart = "" Then Exit Function
            If hasMisplacedDot(leftPart) Then Exit Function
            If hasMisplacedDot(rightPart) Then Exit Function
            GetLegalEmail = leftPart & "@" & rightPart
        Catch ex As Exception
            CoutErr(vbNewLine & "GetLegalEmail: " & ex.Message)
        End Try

    End Function


The error is underlined at eMailParts = anEmail.Split("@", 2)

The error is:

Overload resolution failed because no accessible 'Split' can be called without a narrowing conversion:
    'Public Function Split(separator() As Char, options As System.StringSplitOptions) As String()': Argument matching parameter 'separator' narrows from 'String' to '1-dimensional array of Char'.
    'Public Function Split(separator() As Char, options As System.StringSplitOptions) As String()': Argument matching parameter 'options' narrows from 'Integer' to 'System.StringSplitOptions'.
    'Public Function Split(separator() As Char, count As Integer) As String()': Argument matching parameter 'separator' narrows from 'String' to '1-dimensional array of Char'.


any ideas?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Try changing it to:

    eMailParts = anEmail.Split('@', 2)
Avatar of bryanford
bryanford

ASKER

That got rid of the error however now its underlined only the open bracket and says "Expression Expected"
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that seems to have done the job. Thanks :)

Do you know why this would work in 2003 and not 2005?
Not sure. I can only think that it is a change in the way that strings are stored.