hyTags
HomeHome DocumentationDocumentation

string-replace

Replaces occurrences of a substring or pattern with a replacement string. Either substring or pattern must be provided, but not both.
Parameter
Type
Description
self
String
String to search and modify
substring
String?
Literal substring to match (replaces first occurrence)
pattern
String?
Regular expression pattern to match (replaces all occurrences)
replacement
String
String to replace matches with
return
string
New string with replacements made
Test Case:Replace pattern replaces all occurrences
    <div></div>
    
    <string-new value="a1b2c3">
    <string-replace pattern="[0-9]" replacement="X">
    <assert-equal value="aXbXcX" type="string">
    
    👆 Try to change something!
  • Test Case:Replace substring replaces first occurrence
      <div></div>
      
      <string-new value="hello hello">
      <string-replace substring="hello" replacement="hi">
      <assert-equal value="hi hi" type="string">
      
      👆 Try to change something!
    • Test succeeded Test failed