I'm having trouble reversing a string. Me thinks I've stared at this too long.

Private Sub btnReverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReverse.Click
        Dim strOrgText As String
        Dim strRevText As String
        Dim array As Array

        strOrgText = Me.txtTheString.Text
        array = strOrgText.ToCharArray()

        strRevText = array.Reverse    'Here is my problem

        strRevText = Me.lblResult.Text

    End Sub

Thx

Recommended Answers

strRevText = array.Reverse    'Here is my problem

thats becouse array.Reverse needs an argument and the other thing it does not produce value so you can't assign it to strRevText

strRevText = Me.lblResult.Text

here is problem too , here u do not show the result …

Jump to Post

All 4 Replies

Try this:

Dim input As String = "abc"
        Dim output As String = ""
        Dim CharStr As New Char
        For Each CharStr In input
            output = CharStr & output
        Next
        MessageBox.Show(output)
strRevText = array.Reverse    'Here is my problem

thats becouse array.Reverse needs an argument and the other thing it does not produce value so you can't assign it to strRevText

strRevText = Me.lblResult.Text

here is problem too , here u do not show the result !

after the correction this is ur code

Dim strOrgText As String
        Dim strRevText As [Char]()
        Dim array As Array

        strOrgText = Me.txtTheString.Text
        strRevText = strOrgText.ToCharArray
        [B]array.Reverse(strRevText)   
        Me.lblResult.Text = strRevText[/B]

or u can use StrReverse function like this

Me.lblResult.Text = StrReverse(Me.txtTheString.Text)
commented: works +1

Thanks Manal

Good day!

Maybe this code will help you. Try this.

Dim StrongText as string
Dim ReverseText as string

StringText="This is a string"
ReverseText= StrReverse(StringText)

This will reverse the value of StringText variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.