473,594 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parsing string, leaving words intact

Hello,

I need to parse a long string into no more than 30
character chunks, but I also need to leave the words
intact. Right now, I am using:

For intStart = 1 to Len(strOriginal ) by 30
strPrint = Mid$(strOrigina l, intStart, 30)
Print #detailFile, Tab(1), intStart, Tab(4), strPrint
Next intStart

and it's fine, but splits up some of the words. If I
could figure out how to find the preceding space of the
30 limit, I'd be in good shape. Any thoughts would be
appreciated. Many thanks in advance.

Jul 19 '05 #1
4 4275
Set SP = New StringParser
SP.SetString "This is a test of the string parsing system",30
arrChunks = SP.GetChunks
Set SP = Nothing
For i = 0 To UBound(arrChunk s)
msgbox arrChunks(i)
Next

Class StringParser
Private mintCounter
Private mintBreak
Private marrData
Private mDic

Private Sub Class_Initializ e()
mintBreak = 0
mintCounter = 0
Set mDic = CreateObject("S cripting.Dictio nary")
End Sub

Private Sub Class_Terminate ()
Set mDic = Nothing
End Sub

Public Function GetChunks()
GetChunks = mDic.Items
End Function

Public Sub SetString(strDa ta,intChunkLeng th)
strData = Trim(strData)
If IsNumeric(intCh unkLength) Then
mintBreak = Abs(intChunkLen gth) \ 1
End If
If Len(strData) > 0 And mintBreak > 0 Then
marrData = Split(strData," ")
For i = 0 To UBound(marrData )
strItem = marrData(i)
If Len(strChunk) + Len(strItem) <= mintBreak Then
strChunk = Trim(strChunk & " " & strItem)
Else
AddChunk strChunk
strChunk = strItem
End If
Next
End If
AddChunk strChunk
End Sub

Private Sub AddChunk(strChu nk)
If Len(strChunk) > 0 Then
mintCounter = mintCounter + 1
mDic.Add mintCounter,str Chunk
End If
End Sub
End Class
-dlbjr

Discerning resolutions for the alms
Jul 19 '05 #2
Here's a vb SCRIPT way.

<%
TheString = "I need to parse a long string into no more than 30 character
chunks, but I also need to leave the words intact. Right now, I am using
and it's fine, but splits up some of the words. If I could figure out how
to find the preceding space of the 30 limit, I'd be in good shape. Any
thoughts would be appreciated. Many thanks in advance."

'''clear out any double+ spaces
Do While Instr(TheString , " ") > 0
TheString = Replace(TheStri ng, " ", " ")
Loop

aParts = Split(TheString , " ")
Redim Preserve aParts(29)

For q = 0 To 29
Response.Write aParts(q) & "<br>"
Next
%>

Ray at home

"meldrape" <an*******@disc ussions.microso ft.com> wrote in message
news:04******** *************** *****@phx.gbl.. .
Hello,

I need to parse a long string into no more than 30
character chunks, but I also need to leave the words
intact. Right now, I am using:

For intStart = 1 to Len(strOriginal ) by 30
strPrint = Mid$(strOrigina l, intStart, 30)
Print #detailFile, Tab(1), intStart, Tab(4), strPrint
Next intStart

and it's fine, but splits up some of the words. If I
could figure out how to find the preceding space of the
30 limit, I'd be in good shape. Any thoughts would be
appreciated. Many thanks in advance.

Jul 19 '05 #3
"meldrape" <an*******@disc ussions.microso ft.com> wrote in message
news:04******** *************** *****@phx.gbl.. .
Hello,

I need to parse a long string into no more than 30
character chunks, but I also need to leave the words
intact. Right now, I am using:

For intStart = 1 to Len(strOriginal ) by 30
strPrint = Mid$(strOrigina l, intStart, 30)
Print #detailFile, Tab(1), intStart, Tab(4), strPrint
Next intStart

and it's fine, but splits up some of the words. If I
could figure out how to find the preceding space of the
30 limit, I'd be in good shape. Any thoughts would be
appreciated. Many thanks in advance.


<%
Const s = "Pneumonoultram icroscopicsilic ovolcanoconiosi s is the longest
word in the English dictionary. For those that are interested, it's a
disease of the lungs which is caused by silica dust.
123456789012345 678901234567890 "
Dim re,arr
Set re = New RegExp
re.Global = True
re.Pattern = "\S{30}|.{1,29} (\s|$)"
Set matches = re.execute(s)
Response.Write "<pre>"
For Each match in matches
Response.Write vbTab & match.FirstInde x & vbTab & vbTab & vbTab & vbTab
& match.Value & vbCRLF
Next
Response.Write "</pre>"
%>

Modifying the code to write to a file instead of to the browser is left
as an exercise for the reader.

HTH
-Chris Hohmann
Jul 19 '05 #4
I think I mis-read your question. Sorry about that. I thought you wanted
the first 30 words.

Ray at home

"Ray at <%=sLocation% >" <myfirstname at lane 34 . komm> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Here's a vb SCRIPT way.

<%
TheString = "I need to parse a long string into no more than 30 character
chunks, but I also need to leave the words intact. Right now, I am using
and it's fine, but splits up some of the words. If I could figure out how
to find the preceding space of the 30 limit, I'd be in good shape. Any
thoughts would be appreciated. Many thanks in advance."

'''clear out any double+ spaces
Do While Instr(TheString , " ") > 0
TheString = Replace(TheStri ng, " ", " ")
Loop

aParts = Split(TheString , " ")
Redim Preserve aParts(29)

For q = 0 To 29
Response.Write aParts(q) & "<br>"
Next
%>

Ray at home

"meldrape" <an*******@disc ussions.microso ft.com> wrote in message
news:04******** *************** *****@phx.gbl.. .
Hello,

I need to parse a long string into no more than 30
character chunks, but I also need to leave the words
intact. Right now, I am using:

For intStart = 1 to Len(strOriginal ) by 30
strPrint = Mid$(strOrigina l, intStart, 30)
Print #detailFile, Tab(1), intStart, Tab(4), strPrint
Next intStart

and it's fine, but splits up some of the words. If I
could figure out how to find the preceding space of the
30 limit, I'd be in good shape. Any thoughts would be
appreciated. Many thanks in advance.


Jul 19 '05 #5

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

Similar topics

19
3993
by: ARK | last post by:
I am writing a search program in ASP(VBScript). The user can enter keywords and press submit. The user can separate the keywords by spaces and/or commas and key words may contain plain words, single quoted strings (phrases), double quoted strings (phrases). For example: Keywords: Jack, Jill, Jim, "Timothy Brown", Mary OR
0
1103
by: Bell, Kevin | last post by:
I'm having trouble with something that seems like it should be simple. I need to copy a file, say "abc-1.tif" to another directory, but if it's in there already, I need to transfer it named "abc-2.tif" but I'm going about it all wrong. Here's what doesn't work: (I'll add the copy stuff from shutil after figuring out the basic string manipulation.)
4
1719
by: Hugh | last post by:
Hello, I am having some problems understanding (most likely), parsing a text file. I would like to parse a file like: block1 { stuff; ... stuffN; };
6
22130
by: G. | last post by:
This is an obvious bug in the String.Replace function: //load a XML string into a document XmlDocument doc = new XmlDocument(); doc.LoadXml("<test id='' />"); //Obtain the string again...Converts my '' to ""...strange, but ok. String strXML = doc.OuterXml; //trying to convert back the single quotes to double quotes
32
14803
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
1
1357
by: kellysgirl | last post by:
Im not good at parsing strings....and Ive been driving myslef nuts This is what I need to do....use an if/else statement to validate thata delimeter has been selected. These delimeters being comma, space and cr-lf. Parse text box contents----- Parse string to break out the words involving a loop and 2 pointer variable(old INdex and New INdex)Both start at 0..old index to always point to the current starting postion for the scan and...
13
4481
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple command set consisting of several single letter commands which take no arguments. A few additional single letter commands take arguments:
6
5697
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a * vector<string>. Now, use istringstream to read read each line * from the vector a word at a time.
3
2499
by: yogi_bear_79 | last post by:
I'm sure I have a few things wrong here. But I am stuck on how to do a recurring search. Also my statement cin >quote; acts weird. If I enter more than one word it blows right past cin >findMe; and completes and exits the code. If you string for cin >quote; is one word it behaves correctly or at least in that regard! #include <iostream> #include <string> using namespace std;
0
7947
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7880
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8255
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
8374
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
8010
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
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
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
3868
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...
1
2389
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

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.