Softanza
StartFrançais
Softanza
Reference · stzString

FindFirst()

The first occurrence of the substring: the position(s).

also written: FirstOccurrence · FindFirstSubString · FindFirstOccurrence

Basic examples (2)

Softanza
o1 = new stzString("12*45*78*90")
# the 2nd star from 4
? o1.FindNthST(2, "*", :StartingAt = 4)
# the first star from 4
? o1.FindFirstST("*", :StartingAt = 4)
Output
9
6

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 555_findnthst.ring(opens in a new tab)

Softanza
o1 = new stzString("12*♥*56*♥*")
# the pair spelling
? o1.FindFirstXT("♥", :BoundedBy = [ "*", "*"])
# the string spelling
? o1.FindFirstXT("♥", :BoundedBy = "*")
Output
4
4

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 564_findfirstxt.ring(opens in a new tab)

Scope (7)

Softanza
o1 = new stzString("12♥♥♥67♥♥♥12♥♥♥")
# the 2nd from 3
? o1.FindNthST(2, "♥♥♥", :StartingAt = 3)
# the first from 5
? o1.FindFirstST("♥♥♥", :StartingAt = 5)
# the last from 6
? o1.FindLastST("♥♥♥", :StartingAt = 6)
Output
8
8
13

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 317_using_st_and_std_extension.ring(opens in a new tab)

Softanza
o1 = new stzString("12♥♥♥67♥♥♥12♥♥♥")
# the first from 6
? o1.FindFirstST("♥♥♥", :StartingAt = 6)
# the last from 6
? o1.FindLastST("♥♥♥", :StartingAt = 6)
# the 2nd from 6
? o1.FindNthST(2, "♥♥♥", :StartingAt = 6)
Output
8
13
13

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 323_findfirstst.ring(opens in a new tab)

Softanza
o1 = new stzString("bla {♥♥♥} blaba bla {♥♥♥} blabla")
# the first from 8
? o1.FindFirstST("♥♥♥", :StartingAt = 8)
# the last from 8
? o1.FindLastST("♥♥♥", :Startingat = 8)
# the 2nd from 3
? o1.FindNthST(2, "♥♥♥", :StartingAt = 3)
Output
22
22
22

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 351_findfirstst.ring(opens in a new tab)

Softanza
o1 = new stzString("12♥♥♥67♥♥♥12♥♥♥")
# the first backward from 12
? o1.FindFirstSTD("♥♥♥", :StartingAt = 12, :Backward)
# the last backward from 12
? o1.FindLastSTD("♥♥♥", :StartingAt = 12, :Backward)
# the 2nd backward from 12
? o1.FindNthSTD(2, "♥♥♥", :StartingAt = 12, :Backward)
Output
8
3
3

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 325_findfirststd.ring(opens in a new tab)

Softanza
o1 = new stzString("12♥♥♥67♥♥♥12♥♥♥")
# the 2nd backward from 10 (:Going spelling)
? o1.FindNthSTD(2, "♥♥♥", :StartingAt = 10, :Going = :Backward)
# the first backward from 14 (bare :Backward)
? o1.FindFirstSTD("♥♥♥", :StartingAt = 14, :Backward)
# the last backward from 6 (:Direction spelling)
? o1.FindLastSTD("♥♥♥", :StartingAt = 6, :Direction = :Backward)
Output
3
8
3

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 317_using_st_and_std_extension.ring(opens in a new tab)

Softanza
oAB  = new stzString("ab")
big  = new stzString( oAB.Repeated(1000000) )
# NumberOfChars is 2,000,000
? big.NumberOfChars()
# Contains 'ab' is TRUE
? big.Contains("ab")
# FindFirst 'ab' is 1
? big.FindFirst("ab")
# FindLast 'ab' is 1,999,999
? big.FindLast("ab")
Output
2000000
1
1
1999999

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 999_engine_string_millions_narrated.ring(opens in a new tab)

Softanza
o1 = new stzString("ab_cd_ef_gh")
# the first underscore
? o1.FindFirst("_")
# a missing star from 4
? o1.FindFirstST("*", :StartingAt = 4)
# the underscore from 3
? o1.FindFirstST("_", :StartingAt = 3)
# the last underscore
? o1.FindLast("_")
# no last star
? o1.FindLast("*")
# the 2nd underscore
? o1.FindNth(2, "_")
Output
3
0
3
9
0
6

run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 508_findfirst.ring(opens in a new tab)

The extensions of this method

Each extension, and whether it exists for this method; an extension that exists combines with the others (FindSTCS).

Extension
Exists
What it adds · The names
Q
no
does what the method does, then returns the object, so the call can be chained
QQ
no
chains on the next, more specific type of object (the Q ladder)
QQQ
no
chains on the most specific type of object (the Q ladder)
QRT
no
returns the result as an object of the requested type
CS
yes
takes a case-sensitivity flag · FindFirstCS, FindFirstSTCS
ST
yes
takes the position to start from (StartingAt) · FindFirstST, FindFirstSTD, FindFirstSTCS, FindFirstSTZZ and 1 more
IB
no
takes bounds that are included (IncludingBounds)
XT
yes
the extended form: more parameters than the base method · FindFirstXT
XTT
no
yet another extension: a further extended form, after XT
Z
yes
includes the position in what it returns · FindFirstZ
ZZ
yes
returns positions as sections, [start, end] · FindFirstZZ, FindFirstDZZ, FindFirstSTZZ, FindFirstSTDZZ
W
no
selects by a condition
WF
no
selects by a condition, with the expressive keywords (@NextItem, @PreviousItem...)
D
yes
takes a direction, forward or backward (Directional) · FindFirstD, FindFirstDZZ, FindFirstSTD, FindFirstSTDZZ
F
no
takes a function (the condition or the update is given as a function); the forms document also uses F for the future form, which defers the action
Many
no
works on a collection of items instead of one (the plural form)
Except
no
takes exceptions, what to leave out (the exceptional form)
U
no
returns the result without duplication

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