http://hastebin.com/rilenawake.hs
This is my current content, as you'd suspect it doesn't work. Is there any way to do for instance
"for however many lines in the string..." "show first line" "increase counter"
repeat
Thank you so much!
Your description is not entirely clear. The following code would print the first line of the content of the string:
import httpclient, sequtils, strutils
let article = getContent("http://en.wikipedia.org/wiki/Special:Random")
let articleLines = toSeq(article.splitLines)
echo articleLines[0]
Assuming you want to iterate over all lines in a string, printing each and incrementing a counter each time, use the following code:
import httpclient, strutils
let article = getContent("http://en.wikipedia.org/wiki/Special:Random")
var counter = 0
for line in article.splitLines:
echo line
counter += 1
In either case, splitLines is an iterator (from strutils). In the first example, it is converted into a (random access) sequence using toSeq (from sequtils). In the second example, we iterate over each line it produces using a standard for loop.