如何替换字符串中的字符串Erlang? [英] How to replace characters in string Erlang?
问题描述
{{1401,873063,143916},< 0.16443.0>}
in redis。我正在尝试使用字母a替换此会话中的 {
字符。 OldSessionID = io_lib:format(〜p,[OldSession#session.sid]),
StringForOldSessionID =列表:flatten(OldSessionID),
ejabberd_redis:cmd([[SADD StringForSessionID,StringForUserInfo]]);
我已经尝试过:
重新:替换(N, {, 一个,[全球,{返回,列表}])。
这是一个很好的做法吗?我读到Erlang中的正则表达式并不是一种建议的方式。
您的解决方案有效,如果您很满意你应该保留它。
在我身边我更喜欢列表理解: [case的$ { - >美元; _ - > X端|| X< - StringForOldSessionID]
。 (因为我不需要检查功能文档:o)
I have this piece of code that gets sessionid, make it a string, and then create a set with key as e.g. {{1401,873063,143916},<0.16443.0>}
in redis. I'm trying replace {
characters in this session with letter "a".
OldSessionID= io_lib:format("~p",[OldSession#session.sid]),
StringForOldSessionID = lists:flatten(OldSessionID),
ejabberd_redis:cmd([["SADD", StringForSessionID, StringForUserInfo]]);
I've tried this:
re:replace(N,"{","a",[global,{return,list}]).
Is this a good way of doing this? I read that regexp in Erlang is not a advised way of doing things.
Your solution works, and if you are comfortable with it, you should keep it.
On my side I prefer list comprehension : [case X of ${ -> $a; _ -> X end || X <- StringForOldSessionID ]
. (just because I don't have to check the function documentation :o)
这篇关于如何替换字符串中的字符串Erlang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!