我需要將一個長文本字符串分成幾個大小爲500的字符(不是特殊字符),形成一個包含所有句子的數組,然後放入它們一起被一個特定的字符分隔(例如/ /)。如下:Vbscript:將文本字符串轉換爲小塊並將其放入數組
「這段文字是一個非常大的文字。」
所以,我得到:
arrTxt(0) = "This is"
arrTxt(1) = "a very"
arrTxt(2) = "very large text"
...
最後:
response.write arrTxt(0) & "//" & arrTxt(1) & "//" & arrTxt(2)...
由於我有限的傳統ASP的知識,我來到了一個理想的結果最接近的是以下幾點:
length = 200
strText = "This text is a very very large."
lines = ((Len (input)/length) - 1)
For i = 0 To (Len (lines) - 1)
txt = Left (input, (i * length)) & "/ /"
response.write txt
Next
但是,這會返回一個重複且重疊的文本字符串:「這是/ /這是/ /這是一個te xt // ...
任何想法與VBScript?謝謝!
感謝您的讚賞。不幸的是,它沒有奏效。 'ReDim Preserve arrText(UBound(arrText)+ 1)'中出現以下錯誤「Array fixed or temporarily locked」。還有什麼建議? – afazolo
@afalzolo:我改變了我的代碼,所以它將是一個動態數組而不是固定的 – JMax
Nop,我得到了同樣的錯誤。另外,如果我將變量聲明爲一個字符串(Dim strText **作爲** String),則會出現以下錯誤:「As」中的「期望語句結束」? – afazolo