Vbscript:将文本字符串转换为小块并将其放入数组中

发布于 2024-12-02 10:23:39 字数 708 浏览 0 评论 0原文

我需要大约每 500 个字符(不是特殊字符)将一个长文本字符串分成较小的部分,形成所有句子的数组,然后将它们放在一起,并用特定字符(例如 / /)分隔。内容如下:

“这篇文章是一篇非常非常大的文章。”

所以,我得到:

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

但是,这返回一个重复且重叠的文本字符串:“this is // this is a //这是一段文字 //...

对 vbscript 有什么想法吗?谢谢!

I need to break a long text string into smaller pieces approximately once every 500 characters (not a special character), forming an array of all the sentences and then put them together separated by a specific character (eg / /). Something as follows:

"This text is a very very large text."

So, I get:

arrTxt(0) = "This is"
arrTxt(1) = "a very"
arrTxt(2) = "very large text"
...

And finally:

response.write arrTxt(0) & "//" & arrTxt(1) & "//" & arrTxt(2)...

Due to my limited knowledge of classic asp, the closest I came to a desired result was the following:

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

However, this returns a repeated and overlapping text string: "this is / / this is a / / this is a text //...

Any idea with vbscript? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心↖ 2024-12-09 10:23:39

不使用数组,您可以直接构建字符串

Const LIMIT = 500
Const DELIMITER = "//"
' your input string - String() creates a new string by repeating the second parameter by the given
' number of times
dim INSTRING: INSTRING = String(500, "a") & String(500, "b") & String(500, "c")


dim current: current = Empty
dim rmainder: rmainder = INSTRING 
dim output: output = Empty
' loop while there's still a remaining string
do while len(rmainder) <> 0
    ' get the next 500 characters
    current = left(rmainder, LIMIT)
    ' remove this 500 characters from the remainder, creating a new remainder
    rmainder = right(rmainder, len(rmainder) - len(current))
    ' build the output string
    output  = output  & current & DELIMITER
loop
' remove the lastmost delimiter
output = left(output, len(output) - len(DELIMITER))
' output to page
Response.Write output

如果您确实需要数组,则可以 split(output, DELIMITER)

Without using an array, you can just build the string as you go

Const LIMIT = 500
Const DELIMITER = "//"
' your input string - String() creates a new string by repeating the second parameter by the given
' number of times
dim INSTRING: INSTRING = String(500, "a") & String(500, "b") & String(500, "c")


dim current: current = Empty
dim rmainder: rmainder = INSTRING 
dim output: output = Empty
' loop while there's still a remaining string
do while len(rmainder) <> 0
    ' get the next 500 characters
    current = left(rmainder, LIMIT)
    ' remove this 500 characters from the remainder, creating a new remainder
    rmainder = right(rmainder, len(rmainder) - len(current))
    ' build the output string
    output  = output  & current & DELIMITER
loop
' remove the lastmost delimiter
output = left(output, len(output) - len(DELIMITER))
' output to page
Response.Write output

If you really need an array, you can then split(output, DELIMITER)

撧情箌佬 2024-12-09 10:23:39

这是一个尝试:

Dim strText as String
Dim strTemp as String
Dim arrText()
Dim iSize as Integer
Dim i as Integer

strText = "This text is a very very large."
iSize = Len(stText) / 500
ReDim arrText(iSize)
strTemp = strText

For i from 0 to iSize - 1
  arrText(i) = Left(strTemp, 500)
  strTemp = Mid(strTemp, 501)
Next i

WScript.Echo Join(strTemp, "//")

Here is a try:

Dim strText as String
Dim strTemp as String
Dim arrText()
Dim iSize as Integer
Dim i as Integer

strText = "This text is a very very large."
iSize = Len(stText) / 500
ReDim arrText(iSize)
strTemp = strText

For i from 0 to iSize - 1
  arrText(i) = Left(strTemp, 500)
  strTemp = Mid(strTemp, 501)
Next i

WScript.Echo Join(strTemp, "//")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文