I saw some questions here related to removing double quotes. But it not solved my Issue. They told to use Replace or Trim functions. I used but the problem remains.
My code:
DataTable dt = TypeConveriontHelper.ConvretExcelToDataTable(SourceAppFilePath);
string targetPath = BatchFolderPath + @"\" + "TRANSACT.INX";
StreamWriter wrtr = null;
wrtr = new StreamWriter(targetPath);
for (int x = 0; x < dt.Rows.Count; x++)
{
string rowString = "";
for (int y = 0; y < dt.Columns.Count; y++)
{
if (y == dt.Columns.Count - 1)
{
rowString += "\"" + dt.Rows[x][y].ToString() + "\"";
}
else
{
rowString += "\"" + dt.Rows[x][y].ToString() + "\"~";
}
}
rowString.Replace('"', ' ').Trim();
wrtr.WriteLine(rowString);
}
wrtr.Close();
wrtr.Dispose();
I tried by using rowString.Replace('"', ' ').Trim(); in above code. But double quotes are present as it is. Proveide me a solution. Thanks.
You need to assign it back to
rowString:Strings are immutable.
row.String.Replace(...)will return you a string, since you are not assigning it anything it will get discarded. It will not change the originalrowStringobject.You may use
String.Emptyor""to replace double quotes with an empty string, instead of single space' '. So your statement should be:(Remember to pass double quote as a string
"\"", since the method overload with string.Empty will require both the parameters to be of type string).You may get rid of
Trim()at the end, if you were trying to remove spaces adding duringstring.Replaceat the beginning or end of the string.