PDA

View Full Version : Insert word or words based on conditional statement



JohnnyBravo
12-26-2006, 11:40 AM
I've got a text file a friend of mine sent me with several URLs like thus:


pinot noir
http://www.someurl.com/hobbs/gorillar...noir.com
Spring autumn
http://www.someurl.com/hobbs/gorillar...tumn.com
zinfandel
http://www.someurl.com/hobbs/gorillar...fandel.com


As you can tell by the ellipses, the full URL got truncated somehow. (Some URLs got truncated and some did not). So I've been correcting the truncated ones by hand like this:

pinot noir
http://www.someurl.com/hobbs/gorillarms-pinot-noir.com
Spring autumn
http://www.someurl.com/hobbs/gorillarms-Spring-autumn.com
zinfandel
http://www.someurl.com/hobbs/gorillarms-zinfandel.com

There's too many URLs to correct by hand so now I need to turn to VBA for an appropriate solution.

So basically I need a way to inspect each line. If URL contains ellipses "arms...whatever.com" then replace it with "gorillarms-word1.com" or ""gorillarms-word1-word2.com" as in the example above. I've been searching on Google but nothing that matches situation at hand.

fumei
12-26-2006, 12:27 PM
Yikes.

Hmmmm. Finding the ellipses would not be hard, if this is just text. But would not each replacement be different?

JohnnyBravo
12-26-2006, 04:39 PM
Yikes.

Hmmmm. Finding the ellipses would not be hard, if this is just text. But would not each replacement be different?

Yes they would be. But the word (or words) being inserted is always going to be just above URL . Is that something VBA can do or am I wrong about that?

fumei
12-27-2006, 07:22 PM
It could be done. Questions:

1. Spring autumn becomes Spring-autumn (with hyphen). It will always be thus?

2. The line above the URL, is it a paragraph, that is, is there a paragraph mark between it and the URL?