Is it possible if given a string I could get each character composing that string?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Haskell, strings are just (linked) lists of characters; you can find the line
somewhere in the source of every Haskell implementation. That makes tasks such as finding the first occurence of a certain character (
elemIndex 'a' mystring) or calculating the frequency of each character (map (head &&& length) . group . sort) trivial.Because of this, you can use the usual syntax for lists with strings, too. Actually,
"foo"is just sugar for['f','o','o'], which in turn is just sugar for'f' : 'o' : 'o' : []. You can pattern match, map and fold on them as you like. For instance, if you want to get the element at positionnofmystring, you could usemystring !! n, provided that0 <= n < length mystring.