|
-
May 24th, 2000, 05:04 AM
#1
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!"
-
May 24th, 2000, 05:09 AM
#2
Im just posting because when someone replies i want the answer too.
-
May 24th, 2000, 05:35 AM
#3
transcendental analytic
Replace " ass " instead of "ass"
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 24th, 2000, 07:49 AM
#4
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.
-
May 24th, 2000, 08:11 AM
#5
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 @$$!"
-
May 24th, 2000, 01:27 PM
#6
PowerPoster
Better Solution
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
-
May 24th, 2000, 03:13 PM
#7
transcendental analytic
Oh, i thought you wanted only ass replaced not grass.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 24th, 2000, 10:14 PM
#8
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?
-
May 24th, 2000, 10:21 PM
#9
Fanatic Member
Give this a whirl
Use vbTextCompare instead of vbBinaryCompare.
Code:
Dim xx$, ZZ$
xx = "Chris. Chang Chiew Thou"
Print xx
xx = Replace(xx, "Chiew", "xxxxx", , , vbTextCompare)
Print xx
Iain, thats with an i by the way!
-
May 24th, 2000, 10:35 PM
#10
Fanatic Member
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
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
May 25th, 2000, 03:34 AM
#11
Is there anyways to use these * in it for wildcards?
-
May 25th, 2000, 03:51 AM
#12
transcendental analytic
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.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 25th, 2000, 04:06 AM
#13
Ya i knew that, but is there anyway to use this * with the Replace command?
-
May 25th, 2000, 05:43 AM
#14
transcendental analytic
Don't ask me. I've always wanted to have a instr like function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 25th, 2000, 08:37 AM
#15
PowerPoster
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".
That the reason why you should use the Replace function instead of using the Instr and Mid function.
Code:
Dim xx$, ZZ$
xx = "Chris. Chang Chiew Thou chiew Chiew aaa"
Print xx
xx = Replace(xx, "Chiew", "xxxxx", , , vbTextCompare)
Print xx
-
May 25th, 2000, 08:52 AM
#16
"Replace" is not a know command. I am using vb 4.0.
-
May 25th, 2000, 11:33 AM
#17
Maybe someone said how and i didnt realize it but how do i use the * operator in the replace fuction?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|