View Single Post
Old 11-27-2004, 12:31 PM   #2 (permalink)
zen_tom
Guest
 
I'm not sure what the one in microsoft word is like, but the vb one is

replace (<stringexpression>,<findexpression>,<replaceexpression>,start,count,vbCompareType) as String

Here are some examples showing variations in the count value. I'm replacing i's for x's, always starting at position 1, and replacing 1,2,3 and then finally all (-1) instances of i's with x's:

? replace("a string with characters in it, various text etc.","i","x",1,1,vbTextCompare)
a strxng with characters in it, various text etc.

? replace("a string with characters in it, various text etc.","i","x",1,2,vbTextCompare)
a strxng wxth characters in it, various text etc.

? replace("a string with characters in it, various text etc.","i","x",1,3,vbTextCompare)
a strxng wxth characters xn it, various text etc.

? replace("a string with characters in it, various text etc.","i","x",1,-1,vbTextCompare)
a strxng wxth characters xn xt, varxous text etc.

If you want to count how many times a word appears in a line of text you can either do a regular find, contained in a loop. Or you could tokenise the line into an array of words, load them into a collection and then count how many matched each collection key.

What exactly do you want to do?
 
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40