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


Elixir String.replace_trailing用法及代碼示例

Elixir語言中 String.replace_trailing 相關用法介紹如下。

用法:

replace_trailing(string, match, replacement)
@spec replace_trailing(t(), t(), t()) :: t()

string 中的 replacement 替換所有尾隨出現的 match

如果沒有出現,則返回未觸及的字符串。

如果 match"" ,則此函數引發 ArgumentError 異常:發生這種情況是因為此函數替換了 string 末尾出現的所有 match ,並且不可能替換 "multiple" 出現的 ""

例子

iex> String.replace_trailing("hello world", " world", "")
"hello"
iex> String.replace_trailing("hello world world", " world", "")
"hello"

iex> String.replace_trailing("hello world", " world", " mundo")
"hello mundo"
iex> String.replace_trailing("hello world world", " world", " mundo")
"hello mundo mundo"

相關用法


注:本文由純淨天空篩選整理自elixir-lang.org大神的英文原創作品 String.replace_trailing(string, match, replacement)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。