You must Sign In to post a response.
  • Category: ASP.NET

    Reading text file error?

    Hi,
    I have a small questing in a text file. Sequence is same for all records , I need to read the text file and save it to piped text file.
    Empid:10
    Empname:AA
    City:xyz
    Sal:2000
    //city field is missing in below record
    Empid:11
    Empname:AB
    Sal:3000

    if any one of the field is missing how to save empty value for that field.
    I am using switch case statement.
  • #769741
    While you reading text file and splitting with ":", you can verify the Citi field available or not from the fetched data from text file.

    If not exist the pass City field with empty and continue other fields putting into pipped text file by reading line by line

    var txtFile = '../fileupload/x.txt';
    var file = new File(txtFile);
    file.open("r");
    while (!file.eof) {
    var lninfor= file.readln();
    var lncolumns = lninfor.split(":");
    // you can check here the required column called City, if not exist then add empty value and write into destination file.
    }
    file.close();

    Thanks!
    B.Ramana Reddy


  • Sign In to post your comments