473,498 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to break up a string by character count

say i have a string that is "hello this is my string and i like it very
much" and i want to insert a newline at every 20th character, how could i go
about doing this?
Sep 28 '06 #1
8 4720
Joe Reynolds wrote:
say i have a string that is "hello this is my string and i like it
very much" and i want to insert a newline at every 20th character,
how could i go about doing this?
I'm sure someone will post a regex solution for this, but until then:

dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 28 '06 #2
that just might work

:)
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Joe Reynolds wrote:
>say i have a string that is "hello this is my string and i like it
very much" and i want to insert a newline at every 20th character,
how could i go about doing this?

I'm sure someone will post a regex solution for this, but until then:

dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Sep 28 '06 #3
Bob Barrows [MVP] wrote:
dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring
Won't that put an extra line break at the end, Bob?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Sep 28 '06 #4
that doesnt hurt me

:)

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Bob Barrows [MVP] wrote:
>dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring

Won't that put an extra line break at the end, Bob?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms.

Sep 28 '06 #5
Dave Anderson wrote:
Bob Barrows [MVP] wrote:
>dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring

Won't that put an extra line break at the end, Bob?
Ummmm ... errr. .. I left that as an exercise for the reader ... yeah,
that's the ticket!

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Sep 28 '06 #6

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Joe Reynolds wrote:
say i have a string that is "hello this is my string and i like it
very much" and i want to insert a newline at every 20th character,
how could i go about doing this?

I'm sure someone will post a regex solution for this, but until then:
Here's then:-

s = InsertStringAtInterval(s, vbCrLf, 20))

Function InsertStringAtInterval(rsSource, rsInsert, rlInterval)

Dim rgx
Set rgx = new RegExp
rgx.Pattern = "([\s\S]{" & rlInterval & "})"
rgx.Global = true

InsertStringAtInterval = rgx.Replace(rsSource, "$1" & rsInsert)

End Function
BTW Joe, I still think you should persue a different solution than this.
If you use this in the TD you will actually need:-

s = InsertStringAtInterval(Server.HTMLEncode(s), "<br />", 20))
dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Sep 29 '06 #7
thank you. that works great, but i had another thought (posted a new
question also)
what i want to do is first check the users input. if i find any strings of
characters that are longer than 40 characters that dont contain a space THEN
i would pass it to your function. as long as there is at least 1 space for
every 40 chars, im ok

"Anthony Jones" <An*@yadayadayada.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>Joe Reynolds wrote:
say i have a string that is "hello this is my string and i like it
very much" and i want to insert a newline at every 20th character,
how could i go about doing this?

I'm sure someone will post a regex solution for this, but until then:

Here's then:-

s = InsertStringAtInterval(s, vbCrLf, 20))

Function InsertStringAtInterval(rsSource, rsInsert, rlInterval)

Dim rgx
Set rgx = new RegExp
rgx.Pattern = "([\s\S]{" & rlInterval & "})"
rgx.Global = true

InsertStringAtInterval = rgx.Replace(rsSource, "$1" & rsInsert)

End Function
BTW Joe, I still think you should persue a different solution than this.
If you use this in the TD you will actually need:-

s = InsertStringAtInterval(Server.HTMLEncode(s), "<br />", 20))
>dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Sep 29 '06 #8
every 40 chars, im ok

How did you determine that 40 chars is OK?

Is that when I have my font size set to any of smallest, smaller, medium,
larger or largest in IE, or use anthing but normal in FireFox?

Bob Lehmann
"Joe Reynolds" <js@js.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
thank you. that works great, but i had another thought (posted a new
question also)
what i want to do is first check the users input. if i find any strings of
characters that are longer than 40 characters that dont contain a space
THEN
i would pass it to your function. as long as there is at least 1 space for
every 40 chars, im ok

"Anthony Jones" <An*@yadayadayada.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Joe Reynolds wrote:
say i have a string that is "hello this is my string and i like it
very much" and i want to insert a newline at every 20th character,
how could i go about doing this?

I'm sure someone will post a regex solution for this, but until then:
Here's then:-

s = InsertStringAtInterval(s, vbCrLf, 20))

Function InsertStringAtInterval(rsSource, rsInsert, rlInterval)

Dim rgx
Set rgx = new RegExp
rgx.Pattern = "([\s\S]{" & rlInterval & "})"
rgx.Global = true

InsertStringAtInterval = rgx.Replace(rsSource, "$1" & rsInsert)

End Function
BTW Joe, I still think you should persue a different solution than
this.
If you use this in the TD you will actually need:-

s = InsertStringAtInterval(Server.HTMLEncode(s), "<br />", 20))
dim buffer, i, newstring,s
s="hello this is my string and i like it very much"
buffer=20
for i = 1 to len(s) step 20
newstring=newstring & mid(s,i,20) & vbcrlf
next
msgbox newstring
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Sep 29 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3281
by: JatP | last post by:
hi Everyone I am trying to create a server and client to send files from one side to the other. I can send files from one side to the other using bufferedinput/output streams but when trying to...
19
78745
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
3
26201
by: Kuups | last post by:
Hi! I have a question regarding the count if character within a string like for example I have a string of e.g. 123#123# I would like to determine what is the code? of getting the # sign
40
3144
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
66
5276
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
7
2817
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
3
5073
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
7
4186
by: jeddiki | last post by:
Hi, I am using a function called htmlwrap() which states that it does NOT add a "<br>" to the 70 character line so that it forces a line wrap. ( the script safely wraps long words without...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.