Reversing a String - VB.NET

If you need to reverse the order of characters in a string, here is a simple way to do it:

Dim OurString As String = "thisistext"
Dim CharacterArray() As Char = OurString.ToCharArray()

Array.Reverse(CharacterArray)
OurString = CharacterArray

' Result: "txetsisiht"

Firstly we assign “thisistext” to OurString.  We then create an array, CharacterArray, of type Char.  This means each item of the array will contain a single character value.

We then populate CharacterArray with the contents of OurString with the ToCharArray() method.  This takes each character in OurString and assigns it to it’s own item in CharacterArray.

Then we call the Array.Reverse function, passing to it CharacterArray.  This function takes an array as a parameter and reverses the order of the items.

We then re-assign OurString to equal the now reveresed values of CharacterArray!

This is probably not the most efficient way to reverse a string but it is simple and wrapped up in a function it is quick and easy. If anyone has a more efficient way I’d be interested in hearing about it.

Continue reading » · Rating: · Written on: 06-29-08 · No Comments »

Change the width of my blog

OK then, so that last post I made highlighted that I need to increase the width of my blog. I’ll get on that.UPDATE
So I fixed the width problem by changing my theme.  All is now good.

Continue reading » · Rating: · Written on: 06-24-08 · No Comments »

So it begins

Well I thought it was time to start up a blog, for several reasons.

  1. A place to verbalise my thoughts. This will require that I write in a clear and precise manner which will improve my communication skills
  2. A historical repository of all things cool that I find. If I blog about it, I won’t have to remember what that ‘cool’ thing was in 6 months
  3. An accountability mechanism. I’m looking to list some goals and accomplishments I want to achieve and having it up here will allow the whole world to see it. Kind of puts pressure on me to perform

Anyway stay tuned!

Continue reading » · Rating: · Written on: 06-24-08 · No Comments »