Sunday, October 21, 2007

Reverse string in VB.net

I was trying to find out how to reverse a string in VB.net and after about 45 minutes of trial and error I found out how :)

here it is

I created a form with 1 textbox and 1 button.
I wanted to reverse the text I entered in the textbox
The idea is you convert the text into an array and use the reverse array built in function in VB.net

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim reverse() As Char = Text.ToCharArray() 'identify the dim and convert it to a char array
reverse = TextBox1.Text
Array.Reverse(reverse) 'Reverse the array (our text)
TextBox1.Text = reverse 'Display the result in the same textbox
Clipboard.SetText(TextBox1.Text) 'Store the new text in the clipboard
End Sub

Have phun

1 comment:

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!