如何从 Erlang 中的字符串中获取 ascii 字符

How can I get the ascii characters from a string in Erlang

我知道我可以像这样从一个字母中获取 ascii 字符:

>Letter = "a",
>hd(Letter).
>97

但我需要这样的东西,其中所有的 ascii 字符都被连接起来:

>Letter = "abc",
>hd(Letter).
>979899

除此之外,我知道以下功能 "returns" 一个包含所有 ascii 字符的列表,但我不能将它分配给变量。

>io: format ( "~ w" [ "abc"]).
>[97,98,99]

您可以使用函数 lists:flatmap/2:

> lists:flatmap(fun erlang:integer_to_list/1, "abc").
"979899"

它将给定的函数应用于每个元素,"flattens" 结果,导致连接。