a question regarding loop and string manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yumyu
    New Member
    • Oct 2006
    • 4

    #1

    a question regarding loop and string manipulation

    Hi,

    If i have a Title called " John Smith" and if i press a command button, it changes to "Smith nhoJ"

    How do i do that with loop and string manipulation?

    Thanks
  • Dawoodoz
    New Member
    • Oct 2006
    • 14

    #2
    use the len(string) function to get the length of the string.
    in the first loop you will look at every letter with the mid(string,star t,length) function and see where the space (" ") is.
    use the mid again to take the two words and put them in two new strings.
    reverse one of them by looping and inserting letters from right to left.
    put the two words back together with a space.

    Comment

    • yumyu
      New Member
      • Oct 2006
      • 4

      #3
      Thanks for your reply.

      However i started visual basic not too long ago, and can you please rephrase that in a simplier way.

      Thanks

      Comment

      • scripto
        New Member
        • Oct 2006
        • 143

        #4
        Use the VB function StrReverse()

        StrReverse("ABC ") will give you "CBA"

        Comment

        • willakawill
          Top Contributor
          • Oct 2006
          • 1646

          #5
          This will work:

          Dim stTitle As String
          Dim stFirst As String
          Dim stLast As String

          stTitle = "John Smith"
          stFirst = Left(stTitle, InStr(stTitle, " ") - 1)
          stLast = Right(stTitle, Len(stTitle) - InStr(stTitle, " "))
          stFirst = StrReverse(stFi rst)
          MsgBox stLast & " " & stFirst

          Comment

          Working...