Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

LEGEND ,
May 24, 2006 May 24, 2006
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


TOPICS
Server side applications
593
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2006 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




Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2006 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
>
>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2006 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
>>
>>
>>
>>
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2006 May 25, 2006
LATEST
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?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines