By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

VB.NET reversing a string without using the string Reversal functions

P: 1
Hi,

Brand new to VB.NET and I'm having a problem figuring out this program. I'll try and be descritive as possible.


I have to create a Windows application that contains a single top-level form with two textboxes on it, on positioned above the other. As each character is entered into the upper textbox, the string that has been entered into the upper textbox must appear in the lower textbox, but in reverse. If the input field contains any digits (0 through 9), each such digit must be translated into its corresponding English name reading in correct left-to-right order, followed by a space character. For example, if the string that has been entered into the upper textbox is “abc123def” the string displayed in the lower textbox must be “fedThree Two One cba” I can't use of any string reversal functions that are included so I'm guessing I have to do a recursive reversal?


I'm using WinXP and Visual Studio 2005
Oct 23 '07 #1
Share this Question
Share on Google+
3 Replies


Shashi Sadasivan
Expert 100+
P: 1,435
try this.

Expand|Select|Wrap|Line Numbers
  1. Array.Reverse(textBox1.text.ToCharArray())
if you then want to convert 1 to One and 2 to Two, etc....
use the replace method of the string.

cheers
Oct 23 '07 #2

P: 1
Hey this should do...

One way
:

Public Function ReverseString(ByRef strToReverse As String) As String
Dim result As String = ""
For i As Integer = 0 To strToReverse.Length - 1
result += strToReverse(strToReverse.Length - 1 - i)
Next
Return result
End Function

Another Way :

Public Function ReverseString(ByRef strToReverse As String) As String
Dim swap as Char = ""
For i As Integer = 0 To strToReverse.Length/2
swap = strToReverse(i)
strToReverse(i) = strToReverse(strToReverse.Length - 1 - i)
strToReverse(strToReverse.Length - 1 - i) = swap
Next
End Function
Mar 11 '08 #3

jamesd0142
100+
P: 469
Reverse a textbox.text

Expand|Select|Wrap|Line Numbers
  1.  TextBox2.Clear()
  2.         Dim j As Integer = Len(TextBox1.Text)
  3.         For i As Integer = 0 To Len(TextBox1.Text) - 1
  4.             TextBox2.Text += Mid(TextBox1.Text, j - i, 1)
  5.         Next
  6.  
This should be what you need though...
Expand|Select|Wrap|Line Numbers
  1.    Dim a As String
  2.         TextBox2.Clear()
  3.         Dim j As Integer = Len(TextBox1.Text)
  4.         For i As Integer = 0 To Len(TextBox1.Text) - 1
  5.             a = Mid(TextBox1.Text, j - i, 1)
  6.             If a = "1" Then
  7.                 TextBox2.Text += "ONE "
  8.             ElseIf a = "2" Then
  9.                 TextBox2.Text += "TWO "
  10.                 'elsif...(add all umbers like this...
  11.             Else
  12.                 TextBox2.Text += Mid(TextBox1.Text, j - i, 1)
  13.             End If
  14.         Next
  15.  
Mar 11 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.