473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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

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
3 6067
Shashi Sadasivan
1,435 Expert 1GB
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
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
469 256MB
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

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

Similar topics

74
by: Michael | last post by:
As if we needed another string reversal question. I have a problem with the following code, that I believe should work. int StringReverse(char* psz) { char *p = psz; char *q = psz +...
24
by: ineedyourluvin1 | last post by:
Why does this reverse the string ? Sorry about using namespace std ; It made it easier to read :-) Thanks #include<iostream> using namespace std ; void rev_str( char* str ) {
45
by: Ajay | last post by:
Hi all,can you please tell the most efficient method to reverse a byte.Function should return a byte that is reversed.
8
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. ...
3
by: Babikie | last post by:
Write a program that performs a reverse recursion with following functions. void swop (char,int,int); void reverse (char); void rev(char,int, int); User should enter a string and all character...
2
by: Kelly B | last post by:
I tried to write a code which would reverse the order of words in a given string. I.e if Input String=The C Programming Language Output String=Language Programming C The Here is the code...
16
by: Scott | last post by:
Yeah I know strings == immutable, but question 1 in section 7.14 of "How to think like a computer Scientist" has me trying to reverse one. I've come up with two things, one works almost like it...
16
by: python101 | last post by:
I intend use string and reverse function to build a simple application in python for DNA (presented by A,G,G, and T) mutation when one of its substring is reversed during the replication process. The...
144
by: dominantubergeek | last post by:
Hello, I'm a highly experienced expert C programmer and I've written this code to reverse a string in place. I think you could all learn something from it! int reverse(char* reverseme){ int...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.