Want to remove the double quotes from the strings

Trim can remove any character(s), not just whitespace.

myString = myString.Trim('"');

http://msdn.microsoft.com/en-us/library/d4tt83f9%28v=vs.110%29.aspx


Your issue is a common mistake. Here's what you need to do:

rowString = rowString.Replace('"', ' ').Trim();

Be sure to return your result to a variable (rowString =). If you do not do this, C# will still run the methods but it will not modify the variable. This is the case with any immutable objects.

Example:

rowString.Replace('"', ' ').Trim();

will not modify the actual rowString object.

rowString = rowString.Replace('"', ' ').Trim();

replaces the old value of rowString with the result of the code on the right.

I wrote this answer and just realized that Habib explained the exact same thing above. :)


You need to assign it back to rowString:

rowString = rowString.Replace('"', ' ').Trim();

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 original rowString object.

You may use String.Empty or "" to replace double quotes with an empty string, instead of single space ' '. So your statement should be:

rowString = rowString.Replace("\"", string.Empty).Trim();

(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 during string.Replace at the beginning or end of the string.