1. find or equal test problem

Hi,
I can't figure what the pproblem is in this program. I try to find the 
letter "p"  in the sequence pp. I see that the value is 112 for p .
I have used the find and equal command before but  i don't know what i'm 
not doing

---======================================

include Win32lib.ew
without warning
with trace

--------------------------------------------------------------------------------
--  Window win
constant win = createEx( Window, "Autosize Demo 1", 0, Default, Default, 
403, 337, 0, 0 )
constant Button_BR = createEx( PushButton, "Bottom Right", win, 296, 
272, 88, 24, 0, 0 )

sequence buffer
object line
integer fn, pout, location
atom color, i                 -- the current color
procedure process()
atom p
sequence pp
pp= {"pickel"}

buffer = {}
    location = find("p", pp)
    if equal(pp,"p") then
        p = pp
        end if
    i = sequence(buffer)
    trace(1)
    if equal(location, 1) then
        trace(1)
        line = pp
        else
            trace(1)
    line = "    "& pp
    end if
end procedure
-- run the main
trace(1)
process()
WinMain( win,Normal )

new topic     » topic index » view message » categorize

2. Re: find or equal test problem

sixs wrote:
> 
> Hi,
> I can't figure what the pproblem is in this program. I try to find the 
> letter "p"  in the sequence pp.

The letter "p" doesn't exist in sequence pp. It does, however, exist in
sequence pp[1]. Maybe that's the problem.

-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/

new topic     » goto parent     » topic index » view message » categorize

3. Re: find or equal test problem

Your problem is pp is defined as a sequence inside a sequence - ie. {"xxx"}
and find(x,s) will only find the Whole sequence "xxx" inside {"xxx"} :)

change pp= {"pickel"} to
pp = "pickel"

and the sun will shine again :)

Cheers
Dave

. .. : :: = == == = :: : .. .
Server-Side DB driven web sites,
Software Development
(and part-time games developer)

contact dave_p at purpletiger dot com
or probert.dave at gmail dot com
. .. : :: = == == = :: : .. .

new topic     » goto parent     » topic index » view message » categorize

4. Re: find or equal test problem

sixs wrote:
> 
> Hi,
> I can't figure what the pproblem is in this program. I try to find the 
> letter "p"  in the sequence pp. I see that the value is 112 for p .
> I have used the find and equal command before but  i don't know what i'm 
> not doing

When you write a string in the form "xyz", you are actually coding a sequence of
three integers. "xyz" is exactly the same as {'x', 'y', 'z'}.

So with 

  pp = { "pickle" }

it is the same as 

  pp = { {'p', 'i', 'c', 'k', 'l', 'e'} }

thus the line 

   location = find( "p", pp)

is the same as 

   location = find( {'p'}, { {'p', 'i', 'c', 'k', 'l', 'e'} })

and as you can see, the variable pp does not contain an element that looks like
{'p'} as it only contains one element and that is a sequence of six integers
(letters).

To find a single letter inside a string, use find like this ...

   a = find('x', string)

Note that the X is in single quotes and not double quotes, as that would mean
you are looking for a string as *one* of the elements of the target.

Try the amended code below ...

object line
integer location

procedure process()
 sequence pp

 pp = "pickle"

 location = find('p', pp)
 if equal(location, 1) then
   line = pp
 else
   line = "    " & pp
 end if
end procedure
process()


-- 
Derek Parnell
Melbourne, Australia
irc://irc.sorcery.net:9000/euphoria

new topic     » goto parent     » topic index » view message » categorize

5. Re: find or equal test problem

Thanks for the advice from all. I am trying to find words in  a listing 
or letter document .
I can see how to find  a  comma in a line, but I was trying to find a 
word  like "pickle" in a line of information.  I have created  HTML 
code, found a single character ">" and then compared  what was in 
buffer[found location], length of expected value. I thought that I  
might find a simple way to do it. If you have any advice I would 
appreciate it!
Thanks
Jim

Derek Parnell wrote:

>
>
>posted by: Derek Parnell <ddparnell at bigpond.com>
>
>sixs wrote:
>  
>
>>Hi,
>>I can't figure what the pproblem is in this program. I try to find the 
>>letter "p"  in the sequence pp. I see that the value is 112 for p .
>>I have used the find and equal command before but  i don't know what i'm 
>>not doing
>>    
>>
>When you write a string in the form "xyz", you are actually coding a sequence
>of three integers. "xyz" is exactly the same as {'x', 'y', 'z'}.
>
>So with 
>
>  pp = { "pickle" }
>
>it is the same as 
>
>  pp = { {'p', 'i', 'c', 'k', 'l', 'e'} }
>
>thus the line 
>
>   location = find( "p", pp)
>
>is the same as 
>
>   location = find( {'p'}, { {'p', 'i', 'c', 'k', 'l', 'e'} })
>
>and as you can see, the variable pp does not contain an element that looks like
>{'p'} as it only contains one element and that is a sequence of six integers
>(letters).
>
>To find a single letter inside a string, use find like this ...
>
>   a = find('x', string)
>
>Note that the X is in single quotes and not double quotes, as that would mean
>you are looking for a string as *one* of the elements of the target.
>
>Try the amended code below ...
>
>}}}
<eucode>
>object line
>integer location
>
>procedure process()
> sequence pp
>
> pp = "pickle"
>
> location = find('p', pp)
> if equal(location, 1) then
>   line = pp
> else
>   line = "    " & pp
> end if
>end procedure
>process()
></eucode>
{{{

>
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: find or equal test problem

sixs wrote:
> 
> Thanks for the advice from all. I am trying to find words in  a listing 
> or letter document .

To find a substring inside a string, use the match() function.

  object textline
  integer location
  textline = gets(0)
  location = match("pickle", textline)
  if location > 0 then
     printf(1, "\nPickle was found at column %d\n", location)
  else
     puts(1, "\nNo pickles here!\n")
  end if


-- 
Derek Parnell
Melbourne, Australia
irc://irc.sorcery.net:9000/euphoria

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu