Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

haskell

How to get the first char from a string in Haskell

Gutha Vamsi Krishna

Overview

In this shot, we'll learn how to use Haskell to get the first character from a string. We can use the take function provided by Haskell to get the first character from a string.

Syntax

take n "provide string here"

Here, n denotes the number of characters to get. We provide n = 1 to get the first character from the given string.

Let's see an example:

Example

main::IO()

main = do
  -- get first character from a string
  print(take 1 "hello world")

Explanation

  • Line 5: We print the first character of the string using the function take and pass n as 1.

RELATED TAGS

haskell
RELATED COURSES

View all Courses

Keep Exploring