473,387 Members | 1,572 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,387 software developers and data experts.

reversing a string using a loop

Does anyone know how to reverse a string using a loop?
Nov 21 '05 #1
3 10060
Hi,

first why doesn't

StrReverse( ) work for you?

for example:
TextBox1.Text = StrReverse(TextBox1.Text)

This is a loop that does the same as StrReverse

Dim strToReverse As String
strToReverse = TextBox1.Text
TextBox1.Text = ""
For i As Integer = strToReverse.Length To 1 Step -1
TextBox1.Text &= Mid(strToReverse, i, 1)
Next
hth Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"minguskhan" <mi********@discussions.microsoft.com> schreef in bericht
news:6F**********************************@microsof t.com...
Does anyone know how to reverse a string using a loop?

Nov 21 '05 #2
Thanks for the reply. I know about that and yes it does work. I just heard
there was a way to do it using a loop and I am having trouble getting it to
work.

Regards,

minguskhan

"Peter Proost" wrote:
Hi,

first why doesn't

StrReverse( ) work for you?

for example:
TextBox1.Text = StrReverse(TextBox1.Text)

This is a loop that does the same as StrReverse

Dim strToReverse As String
strToReverse = TextBox1.Text
TextBox1.Text = ""
For i As Integer = strToReverse.Length To 1 Step -1
TextBox1.Text &= Mid(strToReverse, i, 1)
Next
hth Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"minguskhan" <mi********@discussions.microsoft.com> schreef in bericht
news:6F**********************************@microsof t.com...
Does anyone know how to reverse a string using a loop?


Nov 21 '05 #3
How about this?

'-----------------------------------------------------------------------
Option Strict
Imports System

public Class [class]
Public Shared Sub Main

Dim s As String = "Some randomly selected string to reverse"
Console.WriteLine(s)
Console.WriteLine(Reverse(s))

End SUb

Public Shared Function Reverse(s As String) As String
Dim c1() As Char = s.toCharArray
Dim offset As Integer = c1.length - 1
Dim c2(offset) As Char

For ndx As Integer = 0 To offset
c2(offset - ndx) = c1(ndx)
Next

Return New String(c2)
End Function
End Class
'-----------------------------------------------------------------------

"minguskhan" <mi********@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
: Thanks for the reply. I know about that and yes it does work. I just
heard
: there was a way to do it using a loop and I am having trouble getting
it to
: work.
:
: Regards,
:
: minguskhan
:
: "Peter Proost" wrote:
:
: > Hi,
: >
: > first why doesn't
: >
: > StrReverse( ) work for you?
: >
: > for example:
: > TextBox1.Text = StrReverse(TextBox1.Text)
: >
: > This is a loop that does the same as StrReverse
: >
: > Dim strToReverse As String
: > strToReverse = TextBox1.Text
: > TextBox1.Text = ""
: > For i As Integer = strToReverse.Length To 1 Step -1
: > TextBox1.Text &= Mid(strToReverse, i, 1)
: > Next
: >
: >
: > hth Greetz Peter
: >
: > --
: > Programming today is a race between software engineers striving to
build
: > bigger and better idiot-proof programs, and the Universe trying to
produce
: > bigger and better idiots. So far, the Universe is winning.
: >
: >
: > "minguskhan" <mi********@discussions.microsoft.com> schreef in
bericht
: > news:6F**********************************@microsof t.com...
: > > Does anyone know how to reverse a string using a loop?
: >
: >
: >

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kevin | last post by:
Hello, I need to some help in reversing an 2-dimensional array. I am working with gif images and I am trying to make the mirror image. I was hoping that someone could help give me a headstart...
11
by: Tim Marshall | last post by:
I use Terry Kreft's & Stephen Lebans colour dialog procedures for users to pick colours for various control properties in certain apps. Is there a way to take the colour code that is displayed in...
46
by: Albert | last post by:
Why doesn't: #include <stdio.h> void reverse(char, int); main() { char s;
3
by: dru | last post by:
Problem: Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the second with the next to the last, and so on, all the way to the...
4
by: hello12 | last post by:
Hello, I am new to java and i was having a hard time figuring out on how to do certain string manipulations. I was asked to read in a text file and reverse the words. So far, I have put all...
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...
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...
1
by: rajkumarbathula | last post by:
Hi Could any one help me out in reversing rows/elements of DataTable or String or DataList by using any simple statement? Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.