Reputation: 934
I'd like to loop through the characters of a string and see if each is contained in another string. However, String.toList returns a list of Chars, not Strings, which isn't allowed by the String.contains function. Passing the Char to toString doesn't help, is there another way to achieve this goal, or do I just need another approach altogether?
> String.contains (toString 'a') "asdf"
False : Bool
Upvotes: 0
Views: 1732
Reputation: 2122
Use lists of characters directly:
> standard = String.toList "asdf"
['a','s','d','f'] : List Char
> candidateGood = String.toList "asd"
['a','s','d'] : List Char
> candidateBad = String.toList "abc"
['a','b','c'] : List Char
> List.all (\x -> List.member x standard) candidateGood
True : Bool
> List.all (\x -> List.member x standard) candidateBad
False : Bool
Upvotes: 1
Reputation: 6807
Use String.fromChar to convert a character to string.
String.fromChar 'a' -- "a"
String.contains (String.fromChar 'a') "asdf" -- True
Upvotes: 10