Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #15  
Old 10-31-2021, 05:16 PM
Guessed's Avatar
Guessed Guessed is offline how do I replace string 123-4 with 123 4 Windows 10 how do I replace string 123-4 with 123 4 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You don't need RegEx. Identifying the numbers is not the hard part, working out what to do with them is the hard part.

I don't have time to work on this today so I will just give you some tips on how I would handle this.

The problem with spans (page ranges) is that there are understood numbers that could click over and add preceding digits. So I would prepare the trailing numbers by filling in the understood numbers before adding 2. For example
75 transforms to 77
99 transforms to 101
75-9 needs to become 75-79 before we add two to both to make them 77-81.
88-9 needs to become 88-89 then transform to 90-91 then an extra cleanup step to become 90-1
97-9 needs to become 97-99 then transform to 99-101
99-100 transforms to 101-102 and cleans up to 101-2

So the macro workflow should be:
1. Expand all 'understood' numbers to be the actual number by adding the missing digits
2. Add 2 to every number (whether in a span or not)
3. Simplify the spans where length and initial digits match

Look at the arrStr() elements in my earlier code. This gives you two strings for the spans, you can then test the Len("string") and use Left("string",1) to backfill a digit into the understood character position.

To include the spanning number patterns you actually have change this line in my original code
.Text = "[0-9]{1,4}–[0-9]{1,4}"
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I replace string 123-4 with 123 4 Replace characters in a string Marcia Excel Programming 5 05-04-2020 05:15 AM
how do I replace string 123-4 with 123 4 Wildcard replace any string in context with a specified string wardw Word 7 05-07-2018 09:13 AM
how do I replace string 123-4 with 123 4 Replace multiple strings by one same string at once puff Word 2 02-28-2018 11:04 AM
how do I replace string 123-4 with 123 4 Replace characters in a string Anthon Excel Programming 1 11-03-2016 12:48 AM
How to do multiple find and replace in string. PRA007 Word VBA 2 01-06-2016 09:10 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft