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

 Page 1 of 1 [ 3 post ]

Relevant Pages

Powered by phpBB® Forum Software