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


erlang take(String, Characters)用法及代碼示例


take(String, Characters) -> {Leading, Trailing}
OTP 20.0
take(String, Characters, Complement) -> {Leading, Trailing}
OTP 20.0
take(String, Characters, Complement, Dir) -> {Leading, Trailing}
OTP 20.0
類型:
String = unicode:chardata()
Characters = [grapheme_cluster()]
Complement = boolean()
Dir = direction()
Leading = Trailing = unicode:chardata()

String 中獲取字符,隻要這些字符是集合 Characters 的成員或集合 Characters 的補集。 Dir 可以是 leadingtrailing ,指示要從哪個方向獲取字符。

例子:

5> string:take("abc0z123", lists:seq($a,$z)).
{"abc","0z123"}
6> string:take(<<"abc0z123">>, lists:seq($0,$9), true, leading).
{<<"abc">>,<<"0z123">>}
7> string:take("abc0z123", lists:seq($0,$9), false, trailing).
{"abc0z","123"}
8> string:take(<<"abc0z123">>, lists:seq($a,$z), true, trailing).
{<<"abc0z">>,<<"123">>}

相關用法


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