forum-msg-id-135770-edit

Original date:2021-02-13 11:58:28 Edited by: ghaberek Subject: Re: question about find function

Yes, you're looking for match() not find(). There is a fundamental difference in how these work.

The find() function locates an item in a sequence, and with strings each character is an atom that is an item in the sequence, so you're looking for atoms.

? find( 'D', "ABCDEF" ) 
4 
 
? find( "D", "ABCDEF" ) 
0 

The match() function locates a matching subset of a sequence, and so with strings you're looking a partial string match in a larger string.

? match( 'D', "ABCDEF" ) 
-- crashes, expects 'D' to be a sequence 
 
? match( "D", "ABCDEF" ) 
4 
 
? match( "BCD", "ABCDEF" ) 
2 

And you would use find() to locate a string in a sequence of strings, since those strings are items in the sequence.

? find( "DEF", {"ABC","DEF","GHI"} ) 
2 

Hope this helps.

P.S. I agree the documentation needs work. I've asked for help contributing updates and corrections to the documentation. Anyone who wants to offer corrections is free to submit pull requests on GitHub: https://github.com/OpenEuphoria/euphoria/pulls.

-Greg

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu