RE: match() in depth!
- Posted by bensler at mail.com
Feb 24, 2002
> > If we use some symbolic representation of the test sequence above it
> > could be
> > coded as :
> >
> > {TIAtOM}
> >
> > where I've simple replaced each word with a letter representing that
> > word.
> >
> > Thus the find for "is" similarly coded is match({I}, test). This will
> > return 2.
{TIAtOM} = parse("this is a test of match()",32}
^ this should really be {T,I,A,T,O,M}
I = "is"
I[1] = 'i'
> > The scan for the "s" word is coded match({S},test) and returns 0 because
> > there
> > is no "s" word in the test sequence.
>
This is a bit confusing. match({S},test) will not return 0, it will fail
with "variable not defined", because there is no S variable.
> You lost me there. You said match({I}, test), which i understand, but
> that is
> {I}, same as "I", which meets the specs for match() in the help files. I
> used
> {"I"}.
{I} != "I"
{I} = {"is"}
{"I"} = {{'I'}} -- (confused again? :P)
> > May I recommend trying to locate "is" word in a standard Euphoria
> > sequence
> > string by doing :
> >
> > find (" is ", test) -- Note the spaces around the word. This might save
> > you
> > parsing it too often.
>
> I know that works too, same thing about the {" "} though. But about
> parsing
> it too often, i parse the lines once, then each item is a slice, and i
> deparse
> before writing each out again. There is at least one change on each of
> 200,000+ lines, and some have dozens of changes.
The reason I asked if find() was faster than match() is because that is
what I thought, but you confused me with match({"is"},test) :)
find(x,s) will compare x against any ELEMENT of s
match(x,s) will compare x against any SLICE of s
EXAMPLE:
find("the","look for the matching element")
returns 0, because there is no element that matches "the"
find("the",parse("look for the matching element",32))
returns 3
match("the","look for the matching slice")
returns 10
If you're parsing every line, find() should be quite a bit faster.
find("is",parse("this is a test",32))
If you only need to find one word in the string, match() without parsing
is faster.
match(" is "," " & "this is a test" & " ") -- you'll need the
concatenated spaces so you can compare the first and last slices
Chris
|
Not Categorized, Please Help
|
|