Contains()
Whether the string contains the given substring.
also: contain contains includes has contain a word is present occurs in includes has holds is there present in does it have
Basic examples (2)
oS = new stzString("tea rice tea fish")
? oS.Contains("tea")
? oS.NumberOfOccurrence("tea")
? @@( oS.FindAll("tea") )1 2 [ 1, 10 ]
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 05-one-object-any-structure.en.md(opens in a new tab)
# '^' is before 3 in '^^♥^^'
? Q("^^♥^^").ContainsXT("^", :Before = 3)
# '^' is after 2 in '--♥^^'
? Q("--♥^^").ContainsXT("^", :After = 2)1 1
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 175_containsxt.ring(opens in a new tab)
Scope (8)
# a caret after position 2
? Q("^^♥^^").ContainsXT("^", :AfterPosition = 2)
# a caret in the 5..3 span (normalized)
? Q("^^♥^^").ContainsInSection("^", 5, 3)1 1
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 173_containsxt.ring(opens in a new tab)
# '^' occurs before '♥^' in '^^♥^^'
? Q("^^♥^^").ContainsXT("^", :Before = "♥^")
# '^' occurs after '-♥' in '--♥^^'
? Q("--♥^^").ContainsXT("^", :After = "-♥")1 1
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 176_containsxt.ring(opens in a new tab)
# '^' occurs before position 3 in '^^♥^^'
? Q("^^♥^^").ContainsXT("^", :BeforePosition = 3)
# '^' occurs after position 2 in '--♥^^'
? Q("--♥^^").ContainsXT("^", :AfterPosition = 2)1 1
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 174_containsxt.ring(opens in a new tab)
# ContainsAt([1,4,7], '♥') is TRUE
? Q("♥^^♥^^♥").ContainsAt([ 1, 4, 7 ], "♥")
# ContainsXT('♥', :AtPositions=[1,4,7]) is TRUE
? Q("♥^^♥^^♥").ContainsXT("♥", :AtPositions = [ 1, 4, 7 ])1 1
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 178_containsat.ring(opens in a new tab)
o1 = new stzString("•••••••••")
# it does not contain the empty string
? o1.Contains("")
# it does contain a bullet
? o1.Contains("•")0 1
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 235_contains.ring(opens in a new tab)
o1 = new stzString(" Q(@char).IsNumberInString() ")
# it contains @char
? o1.ContainsCS("@char", FALSE)
# ... but not @substring
? o1.ContainsCS("@substring", FALSE)1 0
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 464_containscs.ring(opens in a new tab)
o1 = new stzString("123♥♥678♥♥1234♥♥789")
# a heart in [3, 10]
? o1.ContainsXT( "♥", :InSection = [ 3, 10 ] )
# a heart in any of the sections
? o1.ContainsXT( "♥", :InSections = [ [ 3, 10 ], [ 8, 12 ], [ 14, 19 ] ] )1 1
run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from 103_containsxt.ring(opens in a new tab)
# empty contains nothing
? Q("").Contains('')
# ... not even text
? Q("").Contains('text')
# text does not contain it
? Q("text").Contains('')0 0 0
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 612_dealing_in_emptiness_in_softanza.ring(opens in a new tab)
and 3 more in the tests
The extensions of this method
Each extension, and whether it exists for this method; an extension that exists combines with the others (FindSTCS).
Every example is a test file of the library, run inside the library for this page; only those whose output kept every promise their file wrote are shown.
See also
- The class stzString
- The area's reference: String
- The other methods in these examples: stzString.ContainsAt · stzString.ContainsInSection · stzString.Count · stzString.Find · stzString.FindFirst · stzString.FindLast · stzString.NumberOfChars · stzString.NumberOfOccurrence · stzString.Reversed
- How-to: Check whether a string contains a substring

