MorFologist Posted April 25, 2010 Posted April 25, 2010 In a block of text, I'd like to use substitute to swap out every other occurrence of a text string, or every one within the paragraph except the first. Ideally, I'd like to vary by number of occurrences (every [fourth] is unchanged). Are any of these possible? Example Google stock is through the roof. Will Google exceed all expectations? How high do you think Google will go? Go, Google! could become Google stock is through the roof. Will GOOG exceed all expectations? How high do you think GOOG will go? Go, Google!
comment Posted April 25, 2010 Posted April 25, 2010 To substitute all but the first occurrence of searchString: Let ( [ split = Position ( text ; searchString ; 1 ; 1 ) + Length ( searchString ) ] ; Left ( text ; split ) & Substitute ( Right ( text ; Length ( text ) - split ) ; searchString ; replaceString ) ) To replace (or not) every n-th occurrence, you will need a custom (recursive) function.
LaRetta Posted April 25, 2010 Posted April 25, 2010 Note that the Substitute() function is case sensitive so SearchString in Comment's calculation must be Google and not google.
MorFologist Posted April 25, 2010 Author Posted April 25, 2010 Thanks! This should solve the issue, and give me something to chew on.
Recommended Posts
This topic is 5384 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now