Find text inside a string
Look for a piece of text anywhere in a longer string. These examples match the letters exactly.
occursin
Simple example
Does abc contain b?
Start'abc' · 'b'
Resulttrue
function main()
println(occursin("b", "abc"))
end
main()
true
Advertisements
Everyday examples
Does a ticket marked blue-zone include the word blue?
Start'blue-zone' · 'blue'
Resulttrue
function main()
println(occursin("blue", "blue-zone"))
end
main()
true
Does a shelf marked fruit contain the word milk?
Start'fruit' · 'milk'
Resultfalse
function main()
println(occursin("milk", "fruit"))
end
main()
false
Does the route name East Road include Road?
Start'East Road' · 'Road'
Resulttrue
function main()
println(occursin("Road", "East Road"))
end
main()
true