Reversing the order of substrings

  • Hi Guys,
    I have 2 UDFs and then a sub that uses them to split a string everytime it sees a "/" and then concatenate the substrings into a new string with spaces.
    My problem is that if I have more than 2 substrings, the order is not correct.

    Example: EDMONDS/DAVE will output fine as DAVE EDMONDS but if I try it with EDMONDS/DAVE/STEPHEN it will only output STEPHEN DAVE EDMONDS not DAVE STEPHEN EDMONDS which is how I would like it. I am sure it is a simple change but I just can't see it.
    Any help gratefully received.

    Function Numnames(str As String) As Long
        Numnames = UBound(Split(str, "/")) + 1
         End Function



  • Re: Reversing the order of substrings


    v = Split(str, "/")
      For i = ubound(v)- 1 To 0 Step -1
         x= x & v(I) & " "


  • Re: Reversing the order of substrings

    You could just tweak the calling routine:

    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Reversing the order of substrings

    Here's another possibility..

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!