473,625 Members | 3,253 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 4725
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=newst ring & 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******@NOyah oo.SPAMcomwrote in message
news:%2******** *******@TK2MSFT NGP06.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=newst ring & 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=newst ring & 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**********@s pammotel.comwro te in message
news:%2******** ********@TK2MSF TNGP05.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=newst ring & 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=newst ring & 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******@NOyah oo.SPAMcomwrote in message
news:%2******** *******@TK2MSFT NGP06.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 = InsertStringAtI nterval(s, vbCrLf, 20))

Function InsertStringAtI nterval(rsSourc e, rsInsert, rlInterval)

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

InsertStringAtI nterval = rgx.Replace(rsS ource, "$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 = InsertStringAtI nterval(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=newst ring & 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*@yadayadaya da.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcomwrote in message
news:%2******** *******@TK2MSFT NGP06.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 = InsertStringAtI nterval(s, vbCrLf, 20))

Function InsertStringAtI nterval(rsSourc e, rsInsert, rlInterval)

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

InsertStringAtI nterval = rgx.Replace(rsS ource, "$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 = InsertStringAtI nterval(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=newst ring & 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.comwro te in message
news:%2******** ********@TK2MSF TNGP02.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*@yadayadaya da.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcomwrote in message
news:%2******** *******@TK2MSFT NGP06.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 = InsertStringAtI nterval(s, vbCrLf, 20))

Function InsertStringAtI nterval(rsSourc e, rsInsert, rlInterval)

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

InsertStringAtI nterval = rgx.Replace(rsS ource, "$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 = InsertStringAtI nterval(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=newst ring & 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
3310
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 send normal messages with printwriter my files being sent across are messed up. Empty jpg's are being sent with wrong file sizes. My code as follows: public class TCPServer {
19
78805
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 find one.
3
26222
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
3215
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, including asian languages (chinese, japanese, korean, etc). First of all, strings will be passed to my class methods, some of which based on the language (and on the encoding) might contain characters that require more that a single byte.
66
5334
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 occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
7
2836
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 found a bug that I can't figure out (believe me; I've tried everything and asked for help several times on the IRC-channel). The updateMsg() and iMsg() takes a list of message-lines as argument (or process a string to a list), and it'll output...
3
5087
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 (Java). It stores character strings, and resizes itself to accommodate new strings when needed. Interface: ----------
7
4196
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 destroying html tags which wordwrap has a tendency of doing! )) What I want to do is add that line break so that it DOES force a line wrap - but I am not sure where to insert it in the function
0
8694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8356
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6118
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4089
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
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 we have to send another system
2
1500
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.