我有这个值,例如" 在w3schools.com,您将学习如何建立一个网站。我们提供所有Web开发技术的免费教程。"
我想每20个字符分隔一次字符串,不想破坏这些字。想要的结果如下
" 在w3schools.com " (17个特征)
" 您将了解" (18个特征)
" 建立网站。" (18个特征)
" 我们免费提供" (13个特征)
" 所有网络中的教程" (20个特征)
"的发展" (11个特征)
"的技术" (12个特征)
代码如下
Dim value as String = "At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies."
Dim array() = value.split(" ")
dim length as integer = array.length
Dim eachLine as integer = 0
Dim newString as string = ""
For counter as integer =0 to length -1
if(array(counter).length + eachLine < 20)
newString += " " + array(counter)
eachLine += array(counter).length
else
newString += " " + vbLf
eachLine = 0
end if
Next
结果我得到如下
&#34; 在w3schools.com你&#34;
&#34; 了解如何制作&#34;
&#34; 我们免费提供&#34;
所有网站开发中的&#34; &#34;