1

I get this error: Value of type 'String' cannot be converted to '1-dimensional array of String'

When I try to use the replace function to replace - with an empty space when converting text to md5hash.

This is my code:

    Public Shared Function GetMD5Hash(ByVal TextToHash As String) As String
    If TextToHash = "" Or TextToHash.Length = 0 Then
        Return String.Empty
    End If

    Dim md5 As MD5 = New MD5CryptoServiceProvider()
    Dim toHash As Byte() = Encoding.Default.GetBytes(TextToHash)
    Dim result As Byte() = md5.ComputeHash(toHash)

    Return System.BitConverter.ToString(result)
End Function


Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    Dim tempPassToken As String() = GetMD5Hash(TextBox2.Text).Replace("-", "")
    Dim passMD5 As String = ""

    For i = 0 To tempPassToken.Length - 1
        passMD5 = passMD5 & tempPassToken(i)
    Next
1
  • 1
    You are trying to assign a String to a variable of type String(). Drop the parentheses from tempPassToken so it is not an array. Which also removes the need for the For loop. Commented Apr 7, 2013 at 20:58

1 Answer 1

1

Change this line:

Dim tempPassToken As String() = GetMD5Hash(TextBox2.Text).Replace("-", "")

to this:

Dim tempPassToken As String = GetMD5Hash(TextBox2.Text).Replace("-", "") 

using the parentheses tells the system you are defining an array of strings, not a single string. And, as the error suggests, you can't assign a string to an array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.