Vlad K.
Vlad K.

Reputation: 320

String manipulation in haskell

I've been coding in Java and Python last 3,4 years. Now I decided I want to learn Haskell.

I have a string in the form:

"https://stackoverflow.com/users?page=1&tab=reputation&filter=all"

I need a function that would increment page number:

"https://stackoverflow.com/users?page=2&tab=reputation&filter=all"

and this string to:

"https://stackoverflow.com/users?page=3&tab=reputation&filter=all"

and so on...

I'm very new to Haskell and don't know how to manipulate strings. How to write such a function?

Upvotes: 0

Views: 110

Answers (1)

epsilonhalbe
epsilonhalbe

Reputation: 15959

If you already know the exact position of the number in the String I would recommend using a function

stoverString :: Int -> String
stoverSTring n = "http://stackoverflow.com/users?page="++ show n
               ++"&tab=reputation&filter=all"

and then use map in combination with [Int] to create all the Strings you desire.

Assuming you want to do some downloading - the next function you should look into is mapM a relative of the simple map function that does IO-actions with your list, instead of simple function application for each element of the list.

Upvotes: 1

Related Questions