0

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?

6
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Ranx
0

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


just roughly, untested.


e.g.

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

or something along those lines

0
Sub Main()

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

    End Sub
0

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!

0

>> 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.

0

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

0

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.

:-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.