Re: How do I find strings with wildcards?

From: anon (aslkfj39_at_yahoo.com)
Date: 03/15/04

  • Next message: Duncan Murdoch: "Re: subject: a bug or a feature? const in D-6"
    Date: 14 Mar 2004 15:38:29 -0800
    
    

    <snip>
    > > > You need to define what you are really after a bit more clearly
    > > Ok, I've done a lot of work on it and I've come up with the following, you
    > > should be able to get an idea of what im attempting to do:
    <snip>
    > > If you dont understand anything/have questions about what im trying to do
    > > etc please post! The above is in a very simple scripting language that
    > > everyone that knows delphi should be able to understand.
    > >
    > > As always, thank you for your time!
    >
    > -- Updated Code --
    >
    > After finding and fixing a bunch of errors, I am now unable to find
    > anymore and it still does not work correctly!
    <snip>

    -- Updated Code [2nd time] --
    I'm trying to make a function that picks up a word with an optional
    offset in a string. if the offset is zero then the function will just
    search for the word but if the offset is a number, lets say one, then
    it should search for that word with the offset one. lets look at an
    example:

    string: this is a test
    word: test
    offset: 1

    if the following words are present in string then they should return
    the value found because of the offset being one, the character x is
    used to represent any possible single character:
    test
    txest
    texst
    tesxt
    xest
    txst
    text
    tesx

    My function is able to pick up almost all of the above but it has
    problems with things like texst because no matter where i put the word
    test under it three characters will not line up. Please tell me how to
    modify my code to make it work correctly.

    //{-- the updated code /sunday/march 14/2004/}
    function filter takes string source, string word, integer offset
    returns string
    local integer loop_source = 1
    local integer loop_word = 1
    local integer match = 0
     
    loop
    exitwhen (loop_source > StringLength(source))

    if (SubStringBJ(source, loop_source, loop_source) == SubStringBJ(word,
    loop_word, loop_word)) then
    set match = match + 1
    set loop_source = loop_source + 1
    set loop_word = loop_word + 1
     if (match >= StringLength(word) - offset) then
     return "found"
     endif
    else
    set loop_source = loop_source + 1
    set loop_word = loop_word + 1
    endif

    if (loop_word >= StringLength(word) ) then
    set loop_source = ((loop_source + 1) - StringLength(word))
    set loop_word = 1
    set match = 0
    endif

    endloop

    return "not_found"

    endfunction


  • Next message: Duncan Murdoch: "Re: subject: a bug or a feature? const in D-6"

    Relevant Pages

    • Re: substring finding problem!
      ... banono going right to left without overlap ... <snip naming dropping rant> ... the string. ... something at which C programmers suck because C sucks at it. ...
      (comp.lang.c)
    • Re: Efficency and the standard library
      ... could represent this as a negative string length. ... Heathfield labors mightily to stay inside the Game: ... And so the Combatants turn once more to their game of reading C. ...
      (comp.lang.c)
    • Re: The Philosophy of Programming?
      ... less trivial to ensure that the string length has not been altered. ... > lowers psychological complexity for most intelligent readers. ... For most intelligent programmers, the laziness principal applies. ...
      (comp.programming)
    • Re: A C++ Whishlist
      ... > people from inclusion in a standard. ... > creating their own string class. ... >>don't want an ever increasing size of exception specification on each ...
      (comp.lang.cpp)
    • Re: Generic programming in C
      ... int main ... char buf, ... proper string and the assignment might even be off the end of the array. ... strcpy (offset, (offset + findlen)); ...
      (comp.lang.c)