I was wondering if I can convert a string to a list of characters?
"jt5x=!" -> ["j","t","5","x","=","!"]
Essentially, it would be?
example :: String -> [Char]
You can also convert a string to a list using a separator with the split() method. The separator can be any character you specify. The string will separate based on the separator you provide. For example, you can use a comma, , , as the separator.
You can concatenate a list of strings into a single string with the string method, join() . Call the join() method from 'String to insert' and pass [List of strings] . If you use an empty string '' , [List of strings] is simply concatenated, and if you use a comma , , it makes a comma-delimited string.
The split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.
(Collecting comments into an answer)
Because in haskell, a String
is a list of characters, i.e. [Char]
, just returning the input as given will do.
example = id
does what you want. Note that id
is defined as
id x = x
Your example "jt5x=!" -> ["j","t","5","x","=","!"]
does not match the description: Double quotes ""
enclose String
s not single Char
acters. For characters use single quotes '
. You can type
"jt5x=!" == ['j','t','5','x','=','!']
into GHCi and see it returns True
. Type map (:[]) "jt5x=!"
to actually see ["j","t","5","x","=","!"]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With