There are situations that require reversing the order of characters in a string. In the Listing A example, I show you how to utilize the Reverse method of an array to reverse the order of characters in a particular string.
I initially define two string variables: strOriginalText (to hold the initial text we define) and strReversedText (to hold the value of the strOriginalText in the reverse order). The value of strOriginalText is set to "original text." In order to reverse the value of the text in strOriginalText, I create a character array arrChar and set it to the value of strOriginalText.ToCharArray() method, which allows me to take the value of the strOriginalText and convert it into the array of characters. I then reverse the value of the arrChar by utilizing the Reverse method of the Array class. The resulting value is assigned to the strReversedText string and displayed in the MessageBox.
Miss a tip?
Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!