Skip to main content
Inspiring
May 24, 2006
Question

ASP VBSCRIPT: for a declared string, inserting a line break every N characters

  • May 24, 2006
  • 4 replies
  • 625 views
I'm using ASP VB. I want to insert a VbCr or a VbLf into a declared string
every N characters. FWIW, I want to do this because of an apparent
limitation in MSXML2, which I am using to "scrape" data from webpages that I
control: I'm getting spurious exclamation points (!) where line lengths are
too long. Manually inserting line breaks (which do not render in HTML) seems
to solve the problem. Can someone tell me how to do this?

Put another way, I need to flesh out the following pseudocode:

Dim myString, myCursorPosition, myIncrement
myString ="The quick brown fox jumped over the lazy dog."
myCurrentCursorPosition=0
myIncrement=5 ' I want a line break for every myIncrement

While [there are still remaining characters to walk through in the string
' navigate cursor by myIncrement through myString
...
' insert a VbLf at myCurrentCursorPosition
...
myCurrentCursorPosition = myCurrentCursorPosition + myIncrement
[loop]

Thanks for any help on the syntax here.

-KF


This topic has been closed for replies.

4 replies

Inspiring
May 25, 2006
Can you do a find and replace on the exclamation points?
myString = Replace(myString,"!",vbCrLf)

"Ken Fine" <kenfine@u.washington.edu> wrote in message
news:e52jtc$rnn$1@forums.macromedia.com...
> I'm using ASP VB. I want to insert a VbCr or a VbLf into a declared string
> every N characters. FWIW, I want to do this because of an apparent
> limitation in MSXML2, which I am using to "scrape" data from webpages that
> I control: I'm getting spurious exclamation points (!) where line lengths
> are too long. Manually inserting line breaks (which do not render in HTML)
> seems to solve the problem. Can someone tell me how to do this?


Inspiring
May 24, 2006
This is one possible solution specific to the problem I'm having with MSXML.
Code is inefficient for explanatory clarity.

BodyAsHtmlString = replace(BodyAsHtmlString, "</a>", ("</a>"&vbcrlf))
BodyAsHtmlString = replace(BodyAsHtmlString, "</td>", ("</td>"&vbcrlf))
BodyAsHtmlString = replace(BodyAsHtmlString, "</table>",
("</table>"&vbcrlf))
BodyAsHtmlString = replace(BodyAsHtmlString, "</tr>", ("</tr>"&vbcrlf))
BodyAsHtmlString = replace(BodyAsHtmlString, "</br>", ("</br>"&vbcrlf))

-KF


"Ken Fine" <kenfine@u.washington.edu> wrote in message
news:e52ln5$i7$1@forums.macromedia.com...
> Thanks, this code works just fine. However, I'm realizing that my logic is
> going to need to be a little more sophisticated. The string that I am
> breaking includes HTML code. Inserting a VbCr can mess up the code.
>
> I need a way so that the breaks won't break code. Any ideas? If I could
> identify a char that only appeared in written text, that's one hacky
> solution.
>
> Thanks again,
> -KF
>
> "Julian Roberts" <nospam@charon.co.uk> wrote in message
> news:e52kjj$shd$1@forums.macromedia.com...
>> Try something like
>>
>> for i=0 to len(mySt) step 5
>> mySt=left(mySt,i) & vbcrlf & right(mySt,len(mySt)-i)
>> next
>>
>> --
>> Jules
>> http://www.charon.co.uk/charoncart
>> Charon Cart 3
>> Shopping Cart Extension for Dreamweaver MX/MX 2004
>>
>>
>>
>>
>
>


Inspiring
May 24, 2006
Thanks, this code works just fine. However, I'm realizing that my logic is
going to need to be a little more sophisticated. The string that I am
breaking includes HTML code. Inserting a VbCr can mess up the code.

I need a way so that the breaks won't break code. Any ideas? If I could
identify a char that only appeared in written text, that's one hacky
solution.

Thanks again,
-KF

"Julian Roberts" <nospam@charon.co.uk> wrote in message
news:e52kjj$shd$1@forums.macromedia.com...
> Try something like
>
> for i=0 to len(mySt) step 5
> mySt=left(mySt,i) & vbcrlf & right(mySt,len(mySt)-i)
> next
>
> --
> Jules
> http://www.charon.co.uk/charoncart
> Charon Cart 3
> Shopping Cart Extension for Dreamweaver MX/MX 2004
>
>
>
>


Inspiring
May 24, 2006
Try something like

for i=0 to len(mySt) step 5
mySt=left(mySt,i) & vbcrlf & right(mySt,len(mySt)-i)
next

--
Jules
http://www.charon.co.uk/charoncart
Charon Cart 3
Shopping Cart Extension for Dreamweaver MX/MX 2004