943,649 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 20999
  • VB.NET RSS
Apr 22nd, 2007
0

Reverse a String

Expand Post »
I'm having trouble reversing a string. Me thinks I've stared at this too long.

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub btnReverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReverse.Click
  2. Dim strOrgText As String
  3. Dim strRevText As String
  4. Dim array As Array
  5.  
  6. strOrgText = Me.txtTheString.Text
  7. array = strOrgText.ToCharArray()
  8.  
  9. strRevText = array.Reverse 'Here is my problem
  10.  
  11. strRevText = Me.lblResult.Text
  12.  
  13. End Sub

Thx
Similar Threads
Reputation Points: 42
Solved Threads: 1
Light Poster
hoosier23 is offline Offline
25 posts
since Jun 2006
Apr 22nd, 2007
0

Re: Reverse a String

Try this:
VB.NET Syntax (Toggle Plain Text)
  1. Dim input As String = "abc"
  2. Dim output As String = ""
  3. Dim CharStr As New Char
  4. For Each CharStr In input
  5. output = CharStr & output
  6. Next
  7. MessageBox.Show(output)
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Apr 22nd, 2007
1

Re: Reverse a String

Quote ...
VB.NET Syntax (Toggle Plain Text)
  1. strRevText = array.Reverse 'Here is my problem
thats becouse array.Reverse needs an argument and the other thing it does not produce value so you can't assign it to strRevText

Quote ...
VB.NET Syntax (Toggle Plain Text)
  1. strRevText = Me.lblResult.Text
here is problem too , here u do not show the result !

after the correction this is ur code

Dim strOrgText As String
        Dim strRevText As [Char]()
        Dim array As Array

        strOrgText = Me.txtTheString.Text
        strRevText = strOrgText.ToCharArray
        array.Reverse(strRevText)   
        Me.lblResult.Text = strRevText

or u can use StrReverse function like this

VB.NET Syntax (Toggle Plain Text)
  1. Me.lblResult.Text = StrReverse(Me.txtTheString.Text)
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
Apr 23rd, 2007
0

Re: Reverse a String

Thanks Manal
Reputation Points: 42
Solved Threads: 1
Light Poster
hoosier23 is offline Offline
25 posts
since Jun 2006
Apr 23rd, 2007
0

Re: Reverse a String

Good day!

Maybe this code will help you. Try this.

Dim StrongText as string
Dim ReverseText as string

StringText="This is a string"
ReverseText= StrReverse(StringText)

This will reverse the value of StringText variable.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mhovidz is offline Offline
11 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in VB.NET Forum Timeline: Changing properties of control in Class module
Next Thread in VB.NET Forum Timeline: dropdownlist not firing





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC