A string
is a list of characters in Haskell. We can get the length of the string using the length
function.
length <string_name>
The length
function takes a list as a parameter. Since the string
is a list of characters, we can pass the string as a parameter and get its length.
The length
function returns the length of a string as an integer.
Let's take a look at an example of this.
main::IO()main = dolet str = "Hello from Educative!!!"-- Get the string lengthprint(length str)
str
string.length
function to retrieve the length of the string and print it using the print
statement.