在 Cool 中§
请参见主要文档 in context 了解方法 subst
method subst(|)
将调用者强制转换为 Stringy 并调用 Str.subst。
在 Allomorph 中§
请参见主要文档 in context 了解方法 subst
method subst(Allomorph: |c)
在 Str 中§
请参见主要文档 in context 了解方法 subst
multi method subst(Str: , = "", *)
返回调用者字符串,其中 $matcher 被 $replacement 替换(如果没有找到匹配项,则返回原始字符串)。如果没有提供 $replacement,则使用空字符串(即,删除匹配的字符串)。
subst 有一个就地语法变体,拼写为 s/matcher/replacement/,并且状语从属于 s 或位于匹配器内部。
$matcher 可以是 Regex 或一个文字 Str。类型为 Cool 的非 Str 匹配器参数将被强制转换为 Str 以进行文字匹配。如果使用了 Regex $matcher,则 $/ 特殊变量 将被设置为 Nil(如果没有匹配项)、一个 Match 对象或一个 List 的 Match 对象(如果使用了多重匹配选项,如 :g)。