Hi everyboy! I ran into this assignment that asks me to "create an application that allows the user to enter a word or phrse, then the Label should display that word or phrase backwards in all lowercase.

For example, I enter "I read"
Then the label should display "daer I"

I try to do this with "Substring, Replace, etc", butnone of them work.

Is there any particular method to achieve this assignment?

you can deconstruct the old string starting from the back and create a new string.

just roughly, untested.


for x = 0 to oldstring .length -1
     Newstring &= oldstring.substring(x,1)

or something along those lines

Sub Main()

        Dim original As String = "Reverse Me"
        Dim temp As Char() = original.ToCharArray()
        Dim reversed As String = New String(temp)

    End Sub

That is cool. I made a hangman program for my daughter, and I used a loop to pull out each character into an array. ToCharArray would have been much better!

>> Ranx

Concatenating a string in a loop like that kills performance on an application. You should use a StringBuilder or take the approach apegram did. Every time you append a character it reallocates a new piece of memory for stringsize+1. Now for small strings you can't really tell, but when they get bigger it can wreak havoc on your application.

you can ue this

Dim R = Label1.Text.ToCharArray.Reverse
Label1.Text = String.Join("", R.Cast(Of String).ToArray)

but I'm sure your teacher wants you to do it the hard way (using loops)
to give you better understanding

Hey sknake

thanks mate, am aware of the shortcomings of strings, though was unaware of the flexibility the ToCharArray method (Will be looking into that more :-). was just trying to point the original poster in some sort of direction while i downed my morning coffee.