Thread: [Solved] Changing 1,2,3,15 to 1-3,15
View Single Post
 
Old 08-04-2014, 01:15 PM
Cosmo Cosmo is offline Windows Vista Office 2007
Competent Performer
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Changing 1,2,3,15 to 1-3,15

I have a document with a list of endnotes, and the client wants to consolidate the endnote numbers wherever they appear sequentially. My code already converts the endnotes to text (so that they don't get deleted when the numbers are removed), and now I need to consolidate the numbering, but I am not sure the best way to attack this.

To give an example, the following

This text has several endnotes 1,2,5,6,7,12
___________________
1 This is the first endnote
2 This is the second endnote
....etc.


Should result in

This text has several footnotes 1,2,5-7,12

The numbers will be a combination of endnotes and cross-references, but will be converted to text by the time this code runs.

Does anyone have any ideas to help get me started? Should I loop through the entire document one character at a time? Or maybe use a regex to find each pattern of numbers and commas and parse each result as a list and process?
Reply With Quote