Tried replace, trim but cannot remove the quotation mark from a string C#

后端 未结 3 954
深忆病人
深忆病人 2021-01-26 03:38

I am making a application which can convert a excel file to CSV file.

However, some string contain a quotation mark, so when the CSV exported, some of the String was spl

相关标签:
3条回答
  • 2021-01-26 04:19

    Since strings are immutable in .NET, you can't change their values. That means that a new string is made on every write operation on a string.

    Because of that, every method which 'modifies' a string returns a new string instead. So you have to assign that value:

    HTMLTable = HTMLTable.Replace("\"", ""); 
    
    0 讨论(0)
  • 2021-01-26 04:20

    You need to know, that .Replace doesn't change existing string but return new string after replace operation.

    HTMLTable = HTMLTable.Replace("\"", "");
    

    https://msdn.microsoft.com/pl-pl/library/fk49wtc1(v=vs.110).aspx

    0 讨论(0)
  • 2021-01-26 04:26

    You aren't assigning the result of the Trim or replace to a string.

    You need to do something like

    HtmlTable = HtmlTable.Replace("\"", string.Empty);
    

    Looking at your comment, if you don't like string.Empty then you need to do

    HtmlTable = HtmlTable.Replace("\"", "");
    
    0 讨论(0)
提交回复
热议问题