Elixir中的“?\ s”是什么意思?

Xerus

在有关理解的Elixir文档中,我遇到了以下示例:

iex> for <<c <- " hello world ">>, c != ?\s, into: "", do: <<c>>
"helloworld"

我现在有点理解整个表达式,但是我无法弄清楚“?\ s”是什么意思。我知道它以某种方式匹配并因此过滤掉了空格,但这就是我的理解要结束的地方。

编辑:我现在已经知道它可以解析为32,这是一个空格的字符代码,但是我仍然不知道为什么。

阿列克谢·马蒂什金(Alexei Matiushkin)

char文字用美元符号表示。

Erlang/OTP 22 [erts-10.6.1] [...]

Eshell V10.6.1  (abort with ^G)
1> $\s == 32.
%%⇒ true

用同样的方法有烧焦的文字,根据代码文档的行为完全一样二郎字符文字:

这正是Erlang对Erlang char文字($ a)所做的工作。


基本上?\s(问号后跟空格)完全相同

#               ⇓ space here
iex|1 ▶ ?\s == ? 
warning: found ? followed by code point 0x20 (space), please use ?\s instead

?\s可能没有什么特别的,您可能会看到:

for <<c <- " hello world ">>, c != ?o, into: "", do: <<c>> 
#⇒ " hell wrld "

另外,?c对char文字使用符号:

main> ?\s == ' '
#⇒ true

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章