当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


erlang replace(String, SearchPattern, Replacement)用法及代码示例


replace(String, SearchPattern, Replacement) ->
           [unicode:chardata()]
OTP 20.0
replace(String, SearchPattern, Replacement, Where) ->
           [unicode:chardata()]
OTP 20.0
类型:
String = SearchPattern = Replacement = unicode:chardata()
Where = direction() | all

String 中的 SearchPattern 替换为 ReplacementWhere ,默认 leading ,指示是否要替换 SearchPatternleadingtrailingall 遇到的情况。

可以实现为:

lists:join(Replacement, split(String, SearchPattern, Where)).

例子:

1> string:replace(<<"ab..cd..ef">>, "..", "*").
[<<"ab">>,"*",<<"cd..ef">>]
2> string:replace(<<"ab..cd..ef">>, "..", "*", all).
[<<"ab">>,"*",<<"cd">>,"*",<<"ef">>]

相关用法


注:本文由纯净天空筛选整理自erlang.org大神的英文原创作品 replace(String, SearchPattern, Replacement) -> [unicode:chardata()]。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。