944,172 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1753
  • VB.NET RSS
Nov 5th, 2009
0

Help with Reverse Problem

Expand Post »
In Visual Basic 2008 Express edition: Create a new string replacing the order of the words, from last one to the first one and show it in a text box
Example:
Input: “This is an example”
Output: “example an is This”

I know theres a function to reverse the letters (StrReverse), but the order of the words? Please someone help me out.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RgCz is offline Offline
3 posts
since Nov 2009
Nov 5th, 2009
0
Re: Help with Reverse Problem
I don't know if there are indexing routines, but you can set your starting position at 0. while it is less than the length of the string and the character at that position is blank go to the next starting position
set your ending length to 0 and while the length + position character are not blank and not past the end of the string you increment the length by 1. That identifies the length and position of the next word that you insert into a string array and increment the array by one.
Repeat that process using the new starting position until all the words are added to the array. Initalize a string with the last word in the array, from the next to last word to the beginning add a blank and that word to the string. This will not retain multiple blanks in the reversed string.
Reputation Points: 14
Solved Threads: 12
Junior Poster
kplcjl is offline Offline
146 posts
since Sep 2009
Nov 5th, 2009
1
Re: Help with Reverse Problem
Try it,
VB.NET Syntax (Toggle Plain Text)
  1. Dim s As String = "This is an example"
  2. s = String.Join(" ", s.Split(" ").ToArray().Reverse().ToArray())
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Nov 5th, 2009
0
Re: Help with Reverse Problem
Thanks a lot, it worked perfectly. You just resumed the 30 lines i did in 2 lol. Thanks again.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RgCz is offline Offline
3 posts
since Nov 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Help with class
Next Thread in VB.NET Forum Timeline: Voice Recognition System





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC