Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a break after every x amount of chars?? 1

Status
Not open for further replies.

kloner

Programmer
May 15, 2000
79
AU
Hi all,

In VBSCRIPT, how do you print a &quot;<BR>&quot; after every 15 characters of a string?

eg strTempString = &quot;abcdefghijklmnopqrstuvwxyz123456789098gfjkgdfgkd&quot;

and output would be :
abcdefghijklmno <br>
pqrstuvwxyz1234 <br>
56789098gfjkgdf <br>
gkd

Thanks
kloner
 
Something like:

For i = 1 to Len(YourString)
PartStr = PartStr & Mid(YourString, i, 1)
If i mod 15 = 0 then
PartStr = PartStr & &quot;<br>&quot;
Response.Write PartStr & Chr(13) & Chr(10)
PartStr = &quot;&quot;
End If
Next
If Len(PartStr)>0 Then
Response.Write PartStr
End If

Good luck
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
To speed this up you could loop through the entire string by chunks of 15 rather than 1:
Code:
Dim partStr, numLoops, i
numLoops = Fix(len(YourString)/15) 'round down
For i = 0 to numLoops-1
   Response.Write mid(YourString,(i*15)+1,15) & &quot;<br>&quot;
Next
Response.Write Right(YourString,len(YourString) mod 15)

You may not need the -1 on numloops, this was written on the fly so I didn't test it.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
No more vacation for me :(

FAQ FAQ20-2863
= new Forums.Posting.General.GettingAnswers()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top