當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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()]。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。