2010-07-21 155 views
0

我有一個字符串輸入字符串操作

"abc def 50 ghi jhk lmn 63 op qrst" 

我需要輸出該字符串在反向而不觸摸

"tsrq po 63 nml khj ihg 50 fed cba" 

我創建一個vb函數

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 

端函數的數

問題是我需要將字符串拆分爲+ -10個字符。這樣

" 50 fed cba" 
"nml khj ihg " 
"tsrq po 63 " 

回答

0
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 
+0

你可以做到底格式的休息(休息添加和轉義)。我沒有將這些添加到上面的代碼中... – potatopeelings 2010-07-21 06:13:01