VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 340,164 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 3,955 people online right now. Registration is fast and FREE... Join Now!




Reverse a String

Make a string back to front.

Submitted By: RodgerB
Actions:
Rating:
Views: 3,733

Language: VB.NET

Last Modified: December 11, 2007
Instructions:
1) Copy and paste the function into a class.
2) Read how to call the function.

Snippet


  1. ''' <summary>
  2. ''' Reverses a string.
  3. ''' </summary>
  4. ''' <param name="strToReverse">The string you'd like to reverse.</param>
  5. ''' <returns>The string value of the reversed string.</returns>
  6. ''' <remarks></remarks>
  7.  
  8. Public Function ReverseString(ByRef strToReverse As String) As String
  9.     Dim result As String = ""
  10.     For i As Integer = 0 To strToReverse.Length - 1
  11.         result += strToReverse(strToReverse.Length - 1 - i)
  12.     Next
  13.     Return result
  14. End Function
  15.  
  16. ' Example Usage
  17. MessageBox.Show(ReverseString("Hello World!"))

Copy & Paste


Comments

blobyblobyblob 2007-12-15 18:42:56

People can just write: strreverse("

RodgerB 2007-12-15 20:03:45

a) StrReverse is an obsolete function and isn't considered .NET compliant. b) This function gives a hands on approach as to what is involved with reversing a string. Snippets at are supposed to have some sort of educational value, in this case people can use the same sort of math in other languages such as C++ too. I could have used Array.Reverse() too, but that would defeat the purpose of the educational sentiment produced here.

Donnie1581 2009-11-10 06:02:24

lol I had to do the same thing in one of my projects to check to see if a word or phrase was a palindrome


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month