Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expressions to manipulate text.

Status
Not open for further replies.

Craigieboy

Programmer
May 25, 2001
71
GB
Using regular expressions, does anyone know how to count along 1 long line of text (could be any length) 90 characters and add a carriage return, repeating this process until the end of each line?

I am attempting to display text in a browser, however this long line of text runs off the edge of the page. I need to manipulate the text so that the line is broken into lines of up to 90 characters, thus keeping the text nicely inline with the rest of my document.

Thank you in advance,
Craig
 
Sorry...

It should be noted that the 1 long line of text is being pulled from a database therefore I don't initially have much control over it.

Thanks,
Craig
 
I think you should accomplish the same result simply using a table, and stting its width according to your needs.
That's the easyest way... If you want the hard way, let me know.
 
basically, this will look for any 90 occurances of a word character[A-Za-z0-9_] or space, break it up and concat a vbCrLf and store that into a new string, here called newStr.

dim re, match, matches, newStr, startPt
startPt = 0 'keep track of where to start in the string
set re = new regexp 'create the regexp object
re.global = true 'apply to all of the string
re.pattern = (\w|\s){90} 'this will find the 90 characters
set matches = re.execute(strToSearch)

for each match in matches
newStr = newStr & mid(strToSearch,startPt,match.FirstIndex - startPt) & vbCrLf
startPt = match.FirstIndex
next

I haven't gotten a chance to test this out, but it should work. you might need to work out the match.firstIndex a little bit... (ie: you might need to +1 or -1...)

if you need more info, it's at
hth
leo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top