Efficient way of string manipulation
Author |
Message |
Merli #1 / 3
|
 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 |
|
 |
Dan #2 / 3
|
 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 |
|
 |
Yaniv Sap #3 / 3
|
 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 |
|
|
|