Text Minipulation

G

Guest

Hi there,
I am need of some help for some text minipulation.
At this point, I am able to split text from a textbox at every 500th
character into an array.
But the problem is that this splits words apart.

The current code I am using is:
strArray(lngCount) = Mid$(strText, lngCount * lngLimit + 1, lngLimit)

I have also tried the following, but nothing gives.
strArray(lngCount) = Left(strText, InStrRev(Left(strText, lngCount *
lngLimit + 1), " "))
strArray(lngCount) = Mid$(strText, InStrRev(Left$(strText, lngCount *
lngLimit + 1), " "), lngLimit)


Thanks.
-State
 
G

Guest

I need to be able to do this because as it stands the code cuts the text on
the 500th character, whether or not it is apart of a word or not.
The main reason for this project is to take a large amount of data and break
it up into an array which will then be used to parse the information
accordingly.

Thanks.
-State
 
J

John Nurick

I need to be able to do this because as it stands the code cuts the text on
the 500th character, whether or not it is apart of a word or not.
The main reason for this project is to take a large amount of data and break
it up into an array which will then be used to parse the information
accordingly.

Here's one approach. Each substring becomes an item in a
MatchCollection; you can manipulate it as such, or if necessary put them
into an array.

Dim strText As String
Dim strWorking As String
Dim oRE As Object 'VBScript_RegExp_55.RegExp
Dim oMatches As Object 'VBScript_RegExp_55.MatchCollection '

strText = "String to split..."
Set oRE = CreateObject("VBScript.Regexp")
oRE.Pattern = "\b.{0,500}\b"
'... or maybe "\b.{0,500}(?:\W|$)"
oRE.Multiline = True
oRE.Global = True
Set oMatches = oRE.Execute(strText)
For j = 0 To oMatches.Count - 1
strWorking = oMatches(j)
'do stuff with strWorking
'...
Next

But I'm wondering what's the advantage of chopping the string into
arbitrary chunks of about 500 characters before you start to parse it.
If the units you're interested in are larger than single words, you risk
a unit being split across two elements of the array or collection; if
you're interested in words or smaller units, why not parse the string at
that level right away?
 
T

TC

No, I'm asking: why do you need to cut the text up into chunks & put it
into an array?

"So I can parse it", is not a good reason IMHO. You do not need to cut
text up into chunks (amd put it into an array) before you can parse it.

What are you actually trying to achieve? There might be a better way.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
G

Guest

After some re-coding..this worked.

Thanks for the help, it is much appreciated.

Cheers
-State
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top