2011-09-15 138 views
-3

華我嘗試過,但stucked在這裏我得到INSTR和分裂的頭腦,但我的這兩種方法的arent能夠使它棘手的邏輯需要幫助?

這裏7,2,3,4,9,2我的意思是它的子

的長度
1234567 89 'if its 7(length of sub-string) and 2(next sub-string length) then 
1233456789 ' append into one 

123456 123 ' if its 6(length of sub-string) and 3(next sub string length) then 
123456789   

123 1234 12(last 2 characters 12 may exist or may not) 
123 1234 then ' if its 3(length of substring) and 4(next sub string length) then append into one 

1231234 12 and chech next if its 2 and if next is 2 then append 
123123412 
123456789 12 ' if its 9(length of sub string) and next is 2(next sub string length) then make it like these 
123456789 123456712 split into two taking only first 7 characters 

問題是單元格不會看起來像上面,而是看起來像下面。在這裏,我的意思是如果7,則子串 的下一個長度這將是大串,我必須考慮上述條件並轉移串

123456789 1234567 12 ' if its like these then make it like below 
123456789 123456712 
123 1234 1234567 12 123456789 ' like these then make it like below 
1231234 123456712 123456789 
123456789 12 1234567 'like these then make it like these 
123456789 123456712 1234567 
123456 123 123 1234 123456789 12 'like these then make it like below 
123456123 1231234 1234556789 1234567812 
1234567 1234567 12 123456789 123 1234 123456789 12 ' then make like below 
1234567 123456712 123456789 1231234 123456789 1234567812 
12345678 123456789 1234567 123456789 ' do nothing with these type 

我已經採用分體式試圖

If (Len(text(x)) = 7 And Len(text(x + 1)) = 2) Or (Len(text(x)) = 6 And Len(text(x + 1)) = 3) Then 
text(x) = text(x) & text(x + 1) 
ActiveSheet.Cells(i, "D").Value = ActiveSheet.Cells(i, "D").Value & text(x) 
x = x + 1 
ElseIf (Len(text(x)) = 3 And Len(text(x + 1)) = 4) Then 
If Len(text(x + 2)) = 2 Then 
text(x) = text(x) & text(x + 1) & text(x + 2) 
ActiveSheet.Cells(i, "D").Value = ActiveSheet.Cells(i, "D").Value & text(x) 
Else 
text(x) = text(x) & text(x + 1) 
ActiveSheet.Cells(i, "D").Value = ActiveSheet.Cells(i, "D").Value & text(x) 
End If 
end if 

即時仍然試圖做到這一點,但我需要一些幫助,你們guys.its 10小時我一直在嘗試和其中一個或其他失敗我需要一些幫助!它將不勝感激。由於

+0

小問題請關閉問題,請幫助我的邏輯!請 ! – niko

+0

你想做什麼?如果在那裏甚至有問題,你的問題難以置信。 – CanSpice

+2

Niko。你可能沒有得到答案,因爲你試圖實現的「棘手的邏輯」在你的問題中沒有很好的定義。事實上,這可能就是爲什麼你無法弄清楚如何自己實現它。 –

回答

0

所有我可以建議你的是通過編寫一些簡單的測試用例,同時提高您的實現開始:

#/usr/bin/env python 
# this file is tester.py for testing my super-complicated algorithm 
def algorithm(data): 
    items = split(data) 
    out = items[0] 
    while item in items[1:]: 
     if len(item) in (2, 3): 
      out += item 
     else 
      out += ' ' + item 
    # etc... 
    return out 

assert '123456789 123456712' == algorithm('123456789 1234567 12') 
assert '1231234 123456712 123456789' == algorithm('123 1234 1234567 12 123456789') 
# etc... 

現在,每當你做出改變的時候,你只要運行該文件,看看它是否通過你的測試套件。如果你發現真正的數據問題,然後將其添加到測試...