Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to remove new line Constrains in txtfile using asp.net?
I want to remove my txtfile new line Constrains.Any one can help me??

<<HAWB>>,"940",1899/12/30,"Lemon
","CHINA","0","CHINA","CN","T B S INT'L","KOTHALA","KADULA","SRI LANKA","LK","0","0",1,2.6,3.75,"D",,,2,"N/A","COD VW:30X25X25=3.75KG CN/HK/LKO"
C#
txtMAWB.Text = "";
txtMAWBDate.Text = "";
txtFlight.Text = "";
txtFlightDate.Text = "";
txtNoOfPkgs.Text = "";
txtWeight.Text = "";
lblError.Text = "";
 
List testParse = null;

string[] row =null;
 
try
{      FileUpload1.PostedFile.SaveAs(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "source.txt");
     
    testParse = parseCSV(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "source.txt", 24);
     
    BAL.CSV_temp.newTable1 = new DataTable();
    BAL.CSV_temp.newTable = new DataTable();
     
    //HAWBDetails.DataSource = BAL.CSV_temp.newTable1;
    //HAWBDetails.DataBind();
     
    foreach (string column in testParse[0])
    {
        BAL.CSV_temp.newTable.Columns.Add();
        BAL.CSV_temp.newTable1.Columns.Add();
    }
    
    row = testParse[0];
    BAL.CSV_temp.newTable.Rows.Add(row);
    
    txtMAWB.Text = BAL.CSV_temp.newTable.Rows[0].ItemArray.ElementAt(1).ToString();
    txtMAWBDate.Text = BAL.CSV_temp.newTable.Rows[0].ItemArray.ElementAt(2).ToString();
    txtFlight.Text = BAL.CSV_temp.newTable.Rows[0].ItemArray.ElementAt(3).ToString();
    txtFlightDate.Text = BAL.CSV_temp.newTable.Rows[0].ItemArray.ElementAt(4).ToString();
    txtNoOfPkgs.Text = BAL.CSV_temp.newTable.Rows[0].ItemArray.ElementAt(5).ToString();
    txtWeight.Text = BAL.CSV_temp.newTable.Rows[0].ItemArray.ElementAt(6).ToString();
     
    List testParse1 = testParse.GetRange(1, testParse.Count - 1);
    
    foreach (string[] row1 in testParse1)
    {
        BAL.CSV_temp.newTable1.Rows.Add(row1).ToString().Trim();
    }
     
    //Label3.Text = BAL.CSV_temp.newTable1.Rows[0].ItemArray.ElementAt(6).ToString();
     
    HAWBDetails.DataSource = BAL.CSV_temp.newTable1;
    HAWBDetails.DataBind();
     
    lblError.Text = "";
    }
catch (Exception ex)
{
    lblError.Text = "File contents are not in the correct format";
    ErrorLog el = new ErrorLog();
    el.ErrorRegistry(ex, "CSV_reader.aspx", "Selecting File", "NA", "NA");
}
Posted
Updated 5-Feb-15 21:22pm
v3
Comments
deepankarbhatnagar 6-Feb-15 2:43am    
where is new line here?
[no name] 6-Feb-15 2:45am    
After Lemon word.
deepankarbhatnagar 6-Feb-15 2:44am    
do you have code ?

1 solution

you can replace a newline character with a comma using any one of the following method:

Let sampleStrbe the input string

VB
.
      Dim sampleStr As String="<<HAWB>>,"940",1899/12/30,"Lemon
","CHINA","0","CHINA","CN","T B S INT'L","KOTHALA","KADULA","SRI LANKA","LK","0","0",1,2.6,3.75,"D",,,2,"N/A","COD VW:30X25X25=3.75KG CN/HK/LKO"
      sampleStr.Replace(vbNewLine, ",")
      sampleStr.Replace(Chr(13), ",")
      sampleStr.Replace(Environment.NewLine, ",")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900