From Test-Scratch-Wiki

() रोकना ()? ब्लॉक एक बूलियन ब्लॉक और एक ऑपरेटर ब्लॉक है। ब्लॉक यह बताता है कि पहले पैरामीटर के टेक्स्ट में दूसरे पैरामीटर का टेक्स्ट है या नहीं। तुलना केस-संवेदी नहीं है.

उदाहरण उपयोग

यह जांचना कि क्या इनपुट में एक निश्चित स्ट्रिंग है - सॉफ्ट-चेकिंग के लिए उपयोगी है क्योंकि वास्तविक इनपुट बिल्कुल समान नहीं हो सकता है:

when green flag clicked
switch costume to (bunny v)
ask [What's this animal?] and wait
if <(answer) contains [bunny]?> then //सम्‍मिलित ब्‍लॉक का उपयोग इसके बराबर के बजाय किया जाता है क्योंकि उपयोगकर्ता कह सकता है "ए बन्नी"
    say [Correct!]
else
    say [Nope!]
end

केस संवेदनशीलता

यह ब्लॉक केस संवेदी नहीं है. उदाहरण के लिए:

<[apple banana] contains [apple]?> //रिपोर्ट सच है
<[apple banana] contains [APPLE]?> // रिपोर्ट सच है
<[apple banana] contains [Apple]?> // रिपोर्ट सच है

विशेष मामले

यदि दूसरा तर्क खाली है, तो यह ब्लॉक हमेशा सत्य रिपोर्ट करेगा।

समाधान

define (string1) contains (string2)::custom
set [i v] to [0]
set [j v] to [1]
repeat (length of (string1))
    change [i v] by (1)
    if <(letter (i) of (string1)) = (letter (j) of (string2))> then
        set [j v] to [1]
        repeat until <<not <(letter ((i) + (j)) of (string1)) = (letter (j) of (string2))>> or <(j) > (length of (string2))>>
            change [j v] by (1)
        end
        if <(j) > (length of (string2))> then
            set [result v] to [true]
            stop [this script v]
        end
    end
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.