字符串到字符列表 [英] String to list of characters

查看:97
本文介绍了字符串到字符列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以将字符串转换为字符列表?

I was wondering if I can convert a string to a list of characters?

"jt5x=!" -> ["j","t","5","x","=","!"]

基本上是吗?

example :: String -> [Char]

推荐答案

(将评论收集为答案)

由于在haskell中,String 一个字符列表,即[Char],只需返回给定的输入即可.

Because in haskell, a String is a list of characters, i.e. [Char], just returning the input as given will do.

example = id

做您想要的.请注意,id被定义为

does what you want. Note that id is defined as

id x = x

您的示例"jt5x=!" -> ["j","t","5","x","=","!"]与描述不符:双引号""括起String而不是单个Char行为.对于字符,请使用单引号'.您可以输入

Your example "jt5x=!" -> ["j","t","5","x","=","!"] does not match the description: Double quotes "" enclose Strings not single Characters. For characters use single quotes '. You can type

"jt5x=!" == ['j','t','5','x','=','!']

进入GHCi,并看到它返回True.键入map (:[]) "jt5x=!"即可实际看到["j","t","5","x","=","!"].

into GHCi and see it returns True. Type map (:[]) "jt5x=!" to actually see ["j","t","5","x","=","!"].

这篇关于字符串到字符列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆