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$(strOriginal, 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. 4 4271
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(arrChunks)
msgbox arrChunks(i)
Next
Class StringParser
Private mintCounter
Private mintBreak
Private marrData
Private mDic
Private Sub Class_Initialize()
mintBreak = 0
mintCounter = 0
Set mDic = CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
Set mDic = Nothing
End Sub
Public Function GetChunks()
GetChunks = mDic.Items
End Function
Public Sub SetString(strData,intChunkLength)
strData = Trim(strData)
If IsNumeric(intChunkLength) Then
mintBreak = Abs(intChunkLength) \ 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(strChunk)
If Len(strChunk) > 0 Then
mintCounter = mintCounter + 1
mDic.Add mintCounter,strChunk
End If
End Sub
End Class
-dlbjr
Discerning resolutions for the alms
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(TheString, " ", " ")
Loop
aParts = Split(TheString, " ")
Redim Preserve aParts(29)
For q = 0 To 29
Response.Write aParts(q) & "<br>"
Next
%>
Ray at home
"meldrape" <an*******@discussions.microsoft.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$(strOriginal, 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.
"meldrape" <an*******@discussions.microsoft.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$(strOriginal, 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 = "Pneumonoultramicroscopicsilicovolcanoconiosis 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.
123456789012345678901234567890"
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.FirstIndex & 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
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****************@TK2MSFTNGP11.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(TheString, " ", " ") Loop
aParts = Split(TheString, " ") Redim Preserve aParts(29)
For q = 0 To 29 Response.Write aParts(q) & "<br>" Next %>
Ray at home
"meldrape" <an*******@discussions.microsoft.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$(strOriginal, 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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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,...
|
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...
|
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;
};
|
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...
|
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...
| |
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...
|
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...
|
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
*...
|
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;...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |