1

In the below code i have a string array which holds values like "1,2,3" i want to remove the double quotes and display as 1,2,3.pls help me to do this.

string[] Stocks = StockDetails.ToArray();
string s = string.Join(",", Stocks);
user3930037
  • 27
  • 2
  • 9
  • Just Replace("\"","") – a d Sep 03 '14 at 06:29
  • 2
    I guess you're looking in to the debugger. It will show including the quotes but actually there's not. – Sriram Sakthivel Sep 03 '14 at 06:29
  • Most likely duplicate of http://stackoverflow.com/questions/7482360/replace-with-in-a-string-in-c-sharp which talks about strings shown by debugger... Need sample that explains where `"` are shown (i.e. with result of `Console.WriteLine(s);`) to understand if it is duplicate of "you are observing values in debugger" or not. – Alexei Levenkov Sep 03 '14 at 06:39

2 Answers2

1

If you're having string in this format

string str = "\"1,2,3\"";

..then you can simply remove the double quotation marks using Replace method on string.

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

..this will replace the double quotation from your string, and will return the simple text that is not a double quotes.

More I don't think strings are like this, you're having a look at the actual value of the variable string you're having. When you will use it, it will give you the actual 1, 2, 3 but however, use the above code to remove the quotation .

Rajeesh Menoth
  • 1,704
  • 3
  • 17
  • 33
Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
  • I tried this but it does not remove double quotes my o/p should be 1,2,3 .My actual o/p is "1,2,3" – user3930037 Sep 03 '14 at 06:59
  • Good! Then there is no proble, read the _More_ section of my answer. It has a little bit clarification that this value will not effect your actual value. Don't worry, when you display it, it will be in good format that you want it to be. This is just the value inside the string variable. – Afzaal Ahmad Zeeshan Sep 03 '14 at 07:01
1

You can just use string.Replace

var listOfStrings = StockDetails.Select(s => s.Replace("\"", string.Empty))
                                .ToList();
Sayse
  • 42,633
  • 14
  • 77
  • 146