|
-
Mar 31st, 2005, 02:12 PM
#1
Thread Starter
New Member
Reverse String
I know this may seem pretty simple to most but I need to reverse a string. So like if the user types "WX YZ" I want the output to be "ZY XW" Is there a way to do that using a loop?
Thanks in advance.
-
Mar 31st, 2005, 02:46 PM
#2
Re: Reverse String
VB Code:
Dim s As String = "This is the string"
Dim ReverseString As String = ""
For i As Integer = s.Length - 1 To 0 Step -1
ReverseString &= s.Substring(i, 1)
Next
that should do it, although there may be a better way using the .Reverse property of arrays
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Mar 31st, 2005, 03:05 PM
#3
Re: Reverse String
If you want to do it without a loop...
VB Code:
Dim h As String = "Hello"
Dim chars As Char() = h.ToCharArray
Array.Reverse(chars)
h = New String(chars)
I don't live here any more.
-
Mar 31st, 2005, 04:31 PM
#4
Re: Reverse String
i though you could do it w/o a loop, i just didn't know how to get from the char array back to a string. cool
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Apr 1st, 2005, 10:08 AM
#5
New Member
Re: Reverse String
Hi,
Wont something like the following do it:
Label1.Text = StrReverse(TextBox1.Text)
HTH
Alan
-
Apr 1st, 2005, 10:19 AM
#6
Fanatic Member
Re: Reverse String
That shoud be deprecated these days.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Apr 1st, 2005, 10:48 AM
#7
Re: Reverse String
 Originally Posted by DNA7433
That shoud be deprecated these days.
just curious, but why?
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Apr 1st, 2005, 11:05 AM
#8
Re: Reverse String
 Originally Posted by kebo
just curious, but why?
Because its an old vb6 function you should always use .net .
"The dark side clouds everything. Impossible to see the future is."
-
Apr 1st, 2005, 11:16 AM
#9
Re: Reverse String
 Originally Posted by Asgorath
Because its an old vb6 function you should always use .net .
is it not managed by the CRL?
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Apr 1st, 2005, 11:19 AM
#10
Addicted Member
Re: Reverse String
Is there a guide for these old functions somewhere that points to the appropriate .NET version? For example, I'm being taught in class to use the IsNumeric() function to do some basic validation. Is this a VB6 hold-over? If so, what's the .NET equivalent? I'd love to find a link or document somewhere so that I can lookup whether or not a function/method is a VB6 holdover and find the replacment .NET function/method. I don't really have a frame of reference since I'v done virtually no VB6 programming and what little bit I HAVE done was over 6 years ago.
Thanks,
Steve
Last edited by corwin_ranger; Apr 1st, 2005 at 11:22 AM.
-
Apr 1st, 2005, 11:19 AM
#11
Re: Reverse String
 Originally Posted by kebo
is it not managed by the CRL?
no it is.. but its basically included in the framework for backwards compatibility to help VB6 programmers upgrade apps easier... to make the VB6 to VB.NET upgrade wizard produce less errors you have to fix.. etc...
generally the .net ways you can accomplish the same task tend to be better on performance than the VB6 compatibilty functions (even though I will admin some will show little to no difference over all, possibly in some massive loops or complex coding)
but like I said before, its better just from a .net programmer standpoint if you need to work on C# or something, it will be much easier if you stick to the core of the .net framework
-
Apr 1st, 2005, 11:38 AM
#12
Re: Reverse String
 Originally Posted by kleinma
generally the .net ways you can accomplish the same task tend to be better on performance than the VB6 compatibilty functions (even though I will admin some will show little to no difference over all, possibly in some massive loops or complex coding)
this is probably true but with out taking performance into account,
VB Code:
Label1.Text = StrReverse(TextBox1.Text)
is easier to read and code than
VB Code:
Dim chars As Char() = TextBox1.Text
Array.Reverse(chars)
Label1.Text = New String(chars)
Having said that though, I would still prefer to do it the .net way.
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|