Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Haskell, how can I get a substring of a Text between two indices?

I'm trying to fint the Haskell equivalent of the Python:

>>>"This is a test"[5:9]
'is a'

I'm using the Data.Text module, if that makes any difference.

like image 781
Jonathan Avatar asked Oct 20 '25 21:10

Jonathan


1 Answers

Also, you can define the function in terms of Data.Text.take and drop, both functions from Data.Text library:

slice :: Int -> Int -> Text -> Text
slice a b = (Data.Text.take (b - a)) . (Data.Text.drop a)
like image 77
nicodp Avatar answered Oct 22 '25 15:10

nicodp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!