I tried using the find
function to check for the occurrence of the string "ll"
in the string "hello"
, but it returns "ll"
instead of true
or false
:
"This prints 'll'"
print find "hello" "ll"
Does REBOL's standard library have any functions to check if a string contains another string?
Try this
>> print found? find "hello" "ll"
true
>> print found? find "hello" "abc"
false
@ShixinZeng is correct that there is a FOUND? in Rebol. However, it is simply defined as:
found?: function [
"Returns TRUE if value is not NONE."
value
] [
not none? :value
]
As it is equivalent to not none?
...you could have written:
>> print not none? find "hello" "ll"
true
>> print not none? find "hello" "abc"
false
Or if you want the other bias:
>> print none? find "hello" "ll"
false
>> print none? find "hello" "abc"
true
Intended to help with readability while using FIND. However, I don't like it because it has confusing behavior by working when not used with FIND, e.g.
>> if found? 1 + 2 [print "Well this is odd..."]
Well this is odd...
Since you can just use the result of the FIND in a conditional expression with IF and UNLESS and EITHER, you don't really need it very often...unless you are assigning the result to a variable you really want to be boolean. In which case, I don't mind using NOT NONE? or NONE? as appropriate.
And in my opinion, losing FOUND? from the core would be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With