views:

42

answers:

1

Hi,

I have a string input

"abc def 50 ghi jhk lmn 63 op qrst"

i need to output this string in reverse without touch the numbers

"tsrq po 63 nml khj ihg 50 fed cba"

i created a vb function

function strWords(s,length)
strWords = ""
s = replace(s,")"," ( ")
s = replace(s,"("," ) ")
s = replace(s,"-","- ")
s = replace(s," ( "," ( ")
s = replace(s," ) "," ) ")
dim sArray
sArray = split(s)
counter = 0
for i = 0 to ubound(sArray)
    tempStr = sArray(i)
    counter = counter + len(tempStr)
    if len(tempStr) => 1 then
        if Asc(left(tempStr,1)) => Asc("0") and Asc(left(tempStr,1)) <= Asc("9") then
            strWords = tempStr & " " & strWords
        else
            strWords = StrReverse(tempStr) & " " & strWords
        end if
    end if
    if counter > 20 then 
        strWords =  "<br>" & strWords 
        counter = 0
    end if
next

end function

the problem is that i need to split the string into +-10 char. like this

" 50 fed cba" 
"nml khj ihg " 
"tsrq po 63 "  
A: 
Function strWords(s)

    t = ""
    d = ""

    For i = Len(s) To 1 Step -1
        c = Mid(s, i, 1)
        If Asc(c) >= Asc(0) And Asc(c) <= Asc(9) Then
            d = c + d
        Else
            t = t + d + c
            d = ""
        End If
    Next

    strWords = t + d

End Function
potatopeelings
you can do the rest of the formatting at the end (adding breaks and escaping). I haven't added those to the above code...
potatopeelings