Efficient way of string manipulation 
Author Message
 Efficient way of string manipulation

All help would be greatly appreciated!

If I have a string, lets say: "This is the string." And a word, lets say:
"the", what is the best way to go through the string, find every word "the",
and surround it with the string "<1st word>" and "<2nd word>?  So, it would
turn out as "This is <1st word>the<2nd word> string.".

It could even be a find a replace, keeping the "the" in the string and then
replacing the original "the" with the whole "<1st word> the<2nd word"
phrase, but still, what is the most efficient way of accomplishing this?

TIA,
- Merlin



Sat, 12 Mar 2005 12:34:52 GMT  
 Efficient way of string manipulation

Quote:
> All help would be greatly appreciated!

> If I have a string, lets say: "This is the string." And a word, lets say:
> "the", what is the best way to go through the string, find every word "the",
> and surround it with the string "<1st word>" and "<2nd word>?  So, it would
> turn out as "This is <1st word>the<2nd word> string.".

> It could even be a find a replace, keeping the "the" in the string and then
> replacing the original "the" with the whole "<1st word> the<2nd word"
> phrase, but still, what is the most efficient way of accomplishing this?

> TIA,
> - Merlin

It's late, but wouldne replace do this?
sTemp = Replace("This is the string.", "the", "<1st word>the<2nd word>")


Sat, 12 Mar 2005 12:37:32 GMT  
 Efficient way of string manipulation

Quote:


> > All help would be greatly appreciated!

> > If I have a string, lets say: "This is the string." And a word, lets say:
> > "the", what is the best way to go through the string, find every word "the",
> > and surround it with the string "<1st word>" and "<2nd word>?  So, it would
> > turn out as "This is <1st word>the<2nd word> string.".

> > It could even be a find a replace, keeping the "the" in the string and then
> > replacing the original "the" with the whole "<1st word> the<2nd word"
> > phrase, but still, what is the most efficient way of accomplishing this?

> > TIA,
> > - Merlin

> It's late, but wouldne replace do this?
> sTemp = Replace("This is the string.", "the", "<1st word>the<2nd word>")

Careful, if you intend to replace only WHOLE words, you should:

sTemp = Replace("This is the string.", " the ", " <1st word>the<2nd
word> ")
*note the extra spaces*

And, to deal also with the first/last words:

sSrc = "This is the string."
sTmp1 = " " & sSrc & " "
sTmp2 = Replace(sTmp1, " the ", " <1st word>the<2nd word> ")
sAns = Mid$(sTemp, 2, Len(sTemp)-2)

And, obviously, you'll need to make sure that words followed by
punctuation marks are replaced as well, and so on...

Damn! Life aren't as simple as I thought..  :-(

Yaniv.



Sun, 13 Mar 2005 00:06:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Efficient converting from byte-string to word-string

2. string manipulation, string routines, etc.

3. Efficient string concatination

4. Efficient string concatenation

5. Efficient handling of strings from serial port device?

6. Efficient use of strings (Dim, Redim, and all that)

7. Efficient string handling

8. Most efficient way to strip leading zeros from string

9. String manipulation

10. String Manipulation

11. String/Text Manipulations

12. VBA String Manipulation DLL Missing

 

 
Powered by phpBB® Forum Software