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?
|