BarneyL. BarStin
BarneyL. BarStin

Reputation: 343

How i can split "\n" in haskell?

i have the following text as String:

1. INTRODUCTION
Cerebral venous sinus thrombosis (CVST)

and i only need the second line as string, so i am using the below code

let SecondLine = unwords( tail (splitOn "\n" seccion))

but SecondLine is empty. Someone can help me?

Upvotes: 3

Views: 6525

Answers (3)

karakfa
karakfa

Reputation: 67507

or simply

let (header:second:rest) = lines seccion

Upvotes: 1

Undreren
Undreren

Reputation: 2871

The easiest solution to dropping the first line is to uses lines. It has the following signatures:

lines :: String -> [String]   -- Splits string over newline character

You can therefore get the second line using:

let secondLine = head (tail (lines seccion))

Alternatively, you can use point-free style:

let secondLine = head . tail . lines $ seccion

Upvotes: 4

bipll
bipll

Reputation: 11940

Have you tried to use lines?

let secondLine = (lines seccion) !! 1 in

Upvotes: 14

Related Questions