[Haskell-cafe] Newbie question about Read strings in a line of File

Huong Nguyen hiperfume at gmail.com
Tue Jul 26 10:52:43 EDT 2005

Hello everybody,

Now I am writing a module to handles messages of a system. The
messages are stored in a file. The content of each line of the file
likes this:

   1        001          001           Error message 1
   1        001          002           Error message 2
   1        002          001           Warning message 1

in which: The first word is the language Code (e.g: 1 is English, 2 is
French), the second is type of messages (e.g: 001 is error message,
002 is warning message,etc), the third is the index number of
messages, and the last is the message. I need to read 3 first words of
each line and assign them to 3 variables. After that, I need to show
the error message based on the tuple of those 3 first variable, e.g:
errMsg("1","001","001") = "Error message 1"

At first, I tried to read only one first line of the file as follows:

import Prelude
import List
import Char
import IO

main = do hdl <- openFile "message.txt" ReadMode
               msgLine <-hGetLine hdl
--stdMsg: cut space at the begining of the line.
               let stdMsg = dropWhile(not.isSpace) msgLine
-Assign langCode with the first word of the line.
               let langCode = takeWhile(not.isSpace) stdMsg

However, after that, I do not know how to read second element, third
element of the line. And how to read continuous next line after first?

Please help me. Thanks a lot.

More information about the Haskell-Cafe mailing list