Page 1 of 1 1
Topic Options
#155509 - 2006-01-17 06:00 PM Replace() - A function to quickly replace stuff in stuff
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what bigger the data one uses, that slower the good old join(split($stuff,$stuffToReplace),$stuffThatReplaces) becomes.

I was just playing with wkix32.exe and coded a UDF that made it a var inside a script.
after some 30 mins, had to stop the process.
it just took way too much time.

now, if we had Replace() the processor intensive work could be done inside the kix itself and speed gains would be great with just some 10.000 element arrays.

so, I suggest that you ruud dear add the following:
Replace(WHERE,WHAT,WITH)

the parameters could be:
  • WHERE - string or array. if string, works just like join split. if array, works like ascan() -> replace
  • WHAT - what to replace. if string, replaces this with WITH. if array, replaces each element with corresponding element of WITH
  • WITH - replace with this. if string, replaces all matches by WHAT with this. if array, WHAT must be an array and per element match and replace occurs.
    _________________________
    !

    download KiXnet

  • Top
    #155510 - 2006-01-18 07:13 PM Re: Replace() - A function to quickly replace stuff in stuff
    Stevie Offline
    Starting to like KiXtart
    *****

    Registered: 2002-01-09
    Posts: 199
    You can use regular expressions for replacing data. Most regex engines that I'm aware of (including the VBScript COM one) use a Nondeterministic Finite Automaton (NFA) engine to handle the parsing and data replacement, which you should find runs fast enough to handle those types of tasks relatively quickly.
    _________________________
    Stevie

    Top
    #155511 - 2006-01-18 07:16 PM Re: Replace() - A function to quickly replace stuff in stuff
    Shawn Administrator Offline
    Administrator
    *****

    Registered: 1999-08-13
    Posts: 8611
    Nondeterministic Finite Automaton (NFA) ... hey, I think I married one of those.
    Top
    #155512 - 2006-01-18 10:28 PM Re: Replace() - A function to quickly replace stuff in stuff
    Lonkero Administrator Offline
    KiX Master Guru
    *****

    Registered: 2001-06-05
    Posts: 22346
    Loc: OK
    lol.

    but seriously, I have never got to like regEx.
    and if I could choose between pulling some vbscript com regEx or using kixtart internal replace, I would use the internal one.
    _________________________
    !

    download KiXnet

    Top
    #155513 - 2006-01-19 10:07 AM Re: Replace() - A function to quickly replace stuff in stuff
    Richard H. Administrator Offline
    Administrator
    *****

    Registered: 2000-01-24
    Posts: 4946
    Loc: Leatherhead, Surrey, UK
    Quote:

    Nondeterministic Finite Automaton (NFA) ... hey, I think I married one of those.




    Wow! I married a Finite State Machine (FSM) - are we related?

    Top
    #155514 - 2006-01-19 10:19 AM Re: Replace() - A function to quickly replace stuff in stuff
    Mart Moderator Offline
    KiX Supporter
    *****

    Registered: 2002-03-27
    Posts: 4673
    Loc: The Netherlands
    A build-in replace function would indeed be useful. I'm replacing stuff in stuff now by using a text editor (not that efficient I know but it works for now) and this takes lots of time and is an extra action that with a replace function like jooel suggested could be build into the script that needs the input without weird characters. This eliminates an action and therefore eliminating (some) errors in replacing stuff and speeding things up a bit.

    My two cents are in the bucket. Even a replace UDF would do for the time being.
    _________________________
    Mart

    - Chuck Norris once sold ebay to ebay on ebay.

    Top
    #155515 - 2006-01-19 11:20 AM Re: Replace() - A function to quickly replace stuff in stuff
    Lonkero Administrator Offline
    KiX Master Guru
    *****

    Registered: 2001-06-05
    Posts: 22346
    Loc: OK
    mart, they are there.
    and I even mentioned it in the beginning.
    the problem is not having a replace nor the problem is with just replacing stuff in text file.

    the problem comes when you need to replace huge amount of stuff in huge stuff and do that stuff amount of times.
    _________________________
    !

    download KiXnet

    Top
    #155516 - 2006-01-19 11:49 AM Re: Replace() - A function to quickly replace stuff in stuff
    Mart Moderator Offline
    KiX Supporter
    *****

    Registered: 2002-03-27
    Posts: 4673
    Loc: The Netherlands
    I know there is a replace UDF. Should have been more clear in my post.

    Here's the case.
    We have Symantec antivirus installed on our exchange server. It has some match lists with keywords in it. If a mail body or subject contains at least one of these words the entire message is blocked and put in quarantine. We also have some users receiving huge newsletters which sometimes contain one if the words from a match list in it so it gets put in quarantine when it is sort of a false match. Reading the entire newsletter to find these words is a pain and takes a lot of time. So I put together a script using your stringmatch UDF.
    The problem is that these mails contain quotes and other unwanted characters that crash the script. For now I remove these by hand as also the newline (\n) so it all gets on one line and is accepted by my script. I was thinking of automating this by feeding the mail in txt format to the script. The script would then remove the quotes and new lines and stuff and then do a match against the match list words. A replace function to read the file and remove all the crap would be nice.

    Now I'm thinking of it maybe there is an other way of doing this. Hmmmm...will do some testing with reading the file and the existing replace UDF.

    Anyway I don’t want a refund my two cents for the replace function can stay in the bucket.
    _________________________
    Mart

    - Chuck Norris once sold ebay to ebay on ebay.

    Top
    #155517 - 2006-01-19 12:04 PM Re: Replace() - A function to quickly replace stuff in stuff
    Lonkero Administrator Offline
    KiX Master Guru
    *****

    Registered: 2001-06-05
    Posts: 22346
    Loc: OK
    if you have a crashing script, the problem is in the script.
    _________________________
    !

    download KiXnet

    Top
    #155518 - 2006-01-19 12:50 PM Re: Replace() - A function to quickly replace stuff in stuff
    Mart Moderator Offline
    KiX Supporter
    *****

    Registered: 2002-03-27
    Posts: 4673
    Loc: The Netherlands
    The problem is in both the script and the input.
    The mail contains quotes this gives errors so at least all the quotes should be removed from the text in the mail body.

    But this is off topic. Will do some searching and testing for a different solution.
    I still support a replace function build into the kix exe.
    _________________________
    Mart

    - Chuck Norris once sold ebay to ebay on ebay.

    Top
    #155519 - 2006-01-19 01:04 PM Re: Replace() - A function to quickly replace stuff in stuff
    Lonkero Administrator Offline
    KiX Master Guru
    *****

    Registered: 2001-06-05
    Posts: 22346
    Loc: OK
    quotes are not excuse for script to fail.
    and yes, this is of topic.
    _________________________
    !

    download KiXnet

    Top
    #155520 - 2006-02-21 05:22 PM Re: Replace() - A function to quickly replace stuff in stuff
    Arend_ Offline
    MM club member
    *****

    Registered: 2005-01-17
    Posts: 1896
    Loc: Hilversum, The Netherlands
    My 2 cents for this suggestion. A quick and powerfull replace function would certainly serve it's purpose.
    Top
    Page 1 of 1 1


    Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
    Hop to:
    Shout Box

    Who's Online
    0 registered and 579 anonymous users online.
    Newest Members
    min_seow, Audio, Hoschi, Comet, rrosell
    17881 Registered Users

    Generated in 0.063 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

    Search the board with:
    superb Board Search
    or try with google:
    Google
    Web kixtart.org