Results 1 to 17 of 17

Thread: filter and replace?

  1. #1
    Guest
    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!"

  2. #2
    Guest
    Im just posting because when someone replies i want the answer too.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  4. #4
    Guest
    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.

  5. #5
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    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 @$$!"

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb 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

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  8. #8
    Guest
    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?

  9. #9
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Thumbs up 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!

  10. #10
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    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!)

  11. #11
    Guest
    Is there anyways to use these * in it for wildcards?

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  13. #13
    Guest
    Ya i knew that, but is there anyway to use this * with the Replace command?

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  15. #15
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    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

  16. #16
    Guest
    "Replace" is not a know command. I am using vb 4.0.

  17. #17
    Guest
    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
  •  



Click Here to Expand Forum to Full Width