Does anyone know how to reverse a string using a loop?
reversing a string using a loop
Collapse
This topic is closed.
X
X
-
minguskhanTags: None -
Peter Proost
Re: reversing a string using a loop
Hi,
first why doesn't
StrReverse( ) work for you?
for example:
TextBox1.Text = StrReverse(Text Box1.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.Le ngth To 1 Step -1
TextBox1.Text &= Mid(strToRevers e, 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 " <minguskhan@dis cussions.micros oft.com> schreef in bericht
news:6FC5812C-4A5B-4BD8-A702-D84F7C5317EB@mi crosoft.com...[color=blue]
> Does anyone know how to reverse a string using a loop?[/color]
-
minguskhan
Re: reversing a string using a loop
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:
[color=blue]
> Hi,
>
> first why doesn't
>
> StrReverse( ) work for you?
>
> for example:
> TextBox1.Text = StrReverse(Text Box1.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.Le ngth To 1 Step -1
> TextBox1.Text &= Mid(strToRevers e, 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 " <minguskhan@dis cussions.micros oft.com> schreef in bericht
> news:6FC5812C-4A5B-4BD8-A702-D84F7C5317EB@mi crosoft.com...[color=green]
> > Does anyone know how to reverse a string using a loop?[/color]
>
>
>[/color]
Comment
-
_AnonCoward
Re: reversing a string using a loop
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.WriteLi ne(s)
Console.WriteLi ne(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 " <minguskhan@dis cussions.micros oft.com> wrote in message
news:F6DD1F92-3A34-40E2-972C-E29EEF49EF7C@mi crosoft.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(Text Box1.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.Le ngth To 1 Step -1
: > TextBox1.Text &= Mid(strToRevers e, 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 " <minguskhan@dis cussions.micros oft.com> schreef in
bericht
: > news:6FC5812C-4A5B-4BD8-A702-D84F7C5317EB@mi crosoft.com...
: > > Does anyone know how to reverse a string using a loop?
: >
: >
: >
Comment
Comment