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


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}。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。