ReplaceLeadingChars()
ReplaceLeadingChars(:With = pcNew) -- collapse the leading run of a single repeated char into one instance of pcNew. Examples: "___VAR---" + :With="*" -> "*VAR---" "aaaaHELLO" + :With="A" -> "AHELLO" If there's no run (the first 2 chars differ), the string is returned unchanged.
Basic examples (2)
o1 = new stzString("aaaaah Tunisia---")
o1.ReplaceLeadingChars(:With = "O")
# a-run collapsed to O
? o1.Content()
o1.ReplaceTrailingChars(:With = "!")
# dash-run collapsed to !
? o1.Content()Oh Tunisia--- Oh Tunisia!
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 780_content.ring(opens in a new tab)
o1 = new stzString("___VAR---")
o1.ReplaceLeadingChars(:With = "*")
# leading run collapsed
? o1.Content()
o2 = new stzString("___VAR---")
o2.ReplaceTrailingChars(:With = "*")
# trailing run collapsed
? o2.Content()
o3 = new stzString("___VAR---")
o3.ReplaceLeadingAndTrailingChars(:With = "*")
# both at once
? o3.Content()*VAR--- ___VAR* *VAR*
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 772_content.ring(opens in a new tab)
Scope (1)
o1 = new stzString("Oooooh TunisiammMmmM")
o1.ReplaceLeadingChars(:With = "O")
# case-sensitive: nothing to replace
? o1.Content()
o1.ReplaceTrailingChars(:With = "!")
# same at the tail
? o1.Content()
o2 = new stzString("Oooooh TunisiammMmmM")
o2.ReplaceLeadingCharsCS(:With = "O", :CaseSensitive = FALSE)
# case-blind: Ooooo collapses to O
? o2.Content()
o2.ReplaceTrailingCharsCS(:With = "!", :CaseSensitive = FALSE)
# ... and mmMmmM to !
? o2.Content()Oooooh TunisiammMmmM Oooooh TunisiammMmmM Oh TunisiammMmmM Oh Tunisia!
run on 2026-10-02 04:24 inside the library at commit 0e72e2e2c; taken from 781_content.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).
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.ReplaceLeadingAndTrailingChars · stzString.ReplaceTrailingChars

