Is there a way to filter text and replace it?
Say you use "ass".
I want to block it out and replace it with "@$$" or something like that, but still keep the text.
"Your ass is grass!" > "Your @$$ is grass!"
Printable View
Is there a way to filter text and replace it?
Say you use "ass".
I want to block it out and replace it with "@$$" or something like that, but still keep the text.
"Your ass is grass!" > "Your @$$ is grass!"
Im just posting because when someone replies i want the answer too.
Replace " ass " instead of "ass"
What do you mean?
I want to replace "ass" that's already in a sentence
("Your ass is grass!") to "@$$" ("Your @$$ is grass!"). What I mean is, if you have Napster, and have the filter on, it'll change the f word to "$^##" or something like that.
It seems to me that you would have to use InStr on the text, looking for specific words. Once InStr gives you the position, you can use the Mid$ function along with concatenation to piece together the new text.
Example:
-----------------------------------------------------
Dim MyString As String, NewString As String
Dim MyPos As Integer
MyString = "What a pain in the ass!"
MyPos = Instr(MyString, "ass")
NewString = Mid$(MyString, 1, MyPos - 1) _
& "@$$" & Mid$(MyString, MyPos + 3)
MsgBox NewString
------------------------------------------------------
Upon running this code, the message box should display "What a pain in the @$$!"
This is more better & efficient solution, instead of using the Instr and Mid function to locate the terget character.
:)Code:Dim xx$, ZZ$
xx = "Chris. Chang Chiew Thou"
Print xx
xx = Replace(xx, "Chiew", "xxxxx", , , vbBinaryCompare)
Print xx
Oh, i thought you wanted only ass replaced not grass.
Ok, i got a question. Is there anyway to make the string its looking for NOT case-sensitive. So it would treat ass and aSs the same?
Use vbTextCompare instead of vbBinaryCompare.
Code:Dim xx$, ZZ$
xx = "Chris. Chang Chiew Thou"
Print xx
xx = Replace(xx, "Chiew", "xxxxx", , , vbTextCompare)
Print xx
just include a space before ass in the replace function,
or check the range of the surrounding chrs.
if the ascii range is in the upper case / lower case field then don't replace else (space,.:;!vbcrlf) then replace.
a small function to check the front and back of a word could return a boolean as to whether to replace or not
Is there anyways to use these * in it for wildcards?
Yes, there is the like operator, that compares a string with a patternstring but it only returns true or false depending if the pattern applies or not.
Ya i knew that, but is there anyway to use this * with the Replace command?
Don't ask me. I've always wanted to have a instr like function
That the reason why you should use the Replace function instead of using the Instr and Mid function.Quote:
Originally posted by Matthew Gates
The very first code worked but, what if "ass" is typed twice in the same sentence? What would you do then? Since the code looks for the very first "ass".
Code:Dim xx$, ZZ$
xx = "Chris. Chang Chiew Thou chiew Chiew aaa"
Print xx
xx = Replace(xx, "Chiew", "xxxxx", , , vbTextCompare)
Print xx
"Replace" is not a know command. I am using vb 4.0.
Maybe someone said how and i didnt realize it but how do i use the * operator in the replace fuction?