Re: find or equal test problem
- Posted by Derek Parnell <ddparnell at bigpond.com> May 25, 2005
- 382 views
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