Translate

Thursday, July 28, 2011

Reading data from txt file

static void ReadDateFromTxtFile(Args _args)
{
    #File
    TextIo                  io;
    container               c;
    str               itm, name;
    ;
    io = new TextIo("U:\\Test.txt", #io_read);
    if (!io)
    {
        throw error("Error reading file");
    }
    io.inFieldDelimiter(','); //This can be any delimiter, I'm just using Semicolon as an example
    io.inRecordDelimiter(#delimiterCRLF); //CRLF = Carriage Return Line Feed
    ttsbegin;
    while (io.status() == IO_Status::Ok)
    {
        c = io.read();
        if (io.status() != IO_Status::Ok)
        {
            break;
        }
        itm = conpeek(c, 1);
        name=  conpeek(c, 2);
        info(itm + '-->' + name);
    }
    ttscommit;
}

No comments:

Post a Comment