Help with Reverse Problem

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2009
Posts: 3
Reputation: RgCz is an unknown quantity at this point 
Solved Threads: 0
RgCz RgCz is offline Offline
Newbie Poster

Help with Reverse Problem

 
0
  #1
21 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 42
Reputation: kplcjl is an unknown quantity at this point 
Solved Threads: 5
kplcjl kplcjl is offline Offline
Light Poster
 
0
  #2
21 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 461
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven
 
1
  #3
21 Days Ago
Try it,
  1. Dim s As String = "This is an example"
  2. s = String.Join(" ", s.Split(" ").ToArray().Reverse().ToArray())
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: RgCz is an unknown quantity at this point 
Solved Threads: 0
RgCz RgCz is offline Offline
Newbie Poster
 
0
  #4
21 Days Ago
Thanks a lot, it worked perfectly. You just resumed the 30 lines i did in 2 lol. Thanks again.
Reply With Quote Quick reply to this message  
Reply

Tags
2008, basic, visual

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC