In Erlang when you have a list of printable characters, its a string, but a string is also a list of items and all functions of a list can be applied onto a string. Really, the data structure string doesn't exist in Erlang.
Part of my code needs to be sure that something is not only a list, but it's a string. (A real string). It needs to separate lists e.g. [1,2,3,a,b,"josh"]
, from string e.g. "Muzaaya"
.
The guard expression is_list/1
will say true
for both strings and lists. There is no such guard as is_string/1
and so this means I need a code snippet will make sure that my data is a string.
A string in this case is a list of only printable (alphabetical, both cases, upper and lower), and may contain numbers e.g "Muzaaya2536 618 Joshua"
. I need a code snippet please (Erlang) that will check this for me and ensure that the variable is a string, not just a list. thanks
2条答案
按热度按时间kdfy810k1#
在模块
io_lib
中有两个函数可以帮助您:io_lib:printable_list/1
和io_lib:printable_unicode_list/1
,分别测试参数是否为可打印的latin1或unicode字符列表。0tdrvxhp2#
使用isprint(3)定义的可打印字符--
但你不能用它来保护自己。