-2

I need to delete \, ", [ and ] from this string:

"[\"30001|410000000|400000000|PocketPC_Login|1\",\"30002|420000000|400000000|PocketPC_ChangementZone|1\",\"30003|430000000|400000000|PocketPC_Transactions|1\",\"30004|440000000|400000000|PocketPC_Gestion|1\",\"30005|450000000|400000000|PocketPC_Administration|0\",\"30006|431000000|430000000|PocketPC_TSEntrees|1\"]"

When I do this:

string.Trim(new Char[] { '"', '[', ']', "\\"})

or this:

string.Trim(new Char[] { '"', '[', ']', Convert.ToChar(92)})

the result is always the same:

"30001|410000000|400000000|PocketPC_Login|1\",\"30002|420000000|400000000|PocketPC_ChangementZone|1\",\"30003|430000000|400000000|PocketPC_Transactions|1\",\"30004|440000000|400000000|PocketPC_Gestion|1\",\"30005|450000000|400000000|PocketPC_Administration|0\",\"30006|431000000|430000000|PocketPC_TSEntrees|1"

The \ and " still there. What could I do?

David Zomada
  • 167
  • 1
  • 5
  • 22
  • 6
    `Trim` only removes characters from the beginning and end of a string. You want `Replace`. – juharr Apr 06 '21 at 15:29
  • 4
    The slash isn't actually part of your string. Your debugger is just showing that the inner quotes are escaped. –  Apr 06 '21 at 15:30
  • Does this answer your question? [Stop visual studio debug putting slash in string containing double quotes](https://stackoverflow.com/questions/41172620/stop-visual-studio-debug-putting-slash-in-string-containing-double-quotes) – ProgrammingLlama Apr 06 '21 at 15:32

1 Answers1

3

Trim only removes items at the start or the end of a string. You should use a chain of string.Replace.

myString
   .Replace("\\", String.Empty)
   .Replace("\"", String.Empty)
   .Replace("[", String.Empty)
   .Replace("]", String.Empty);

Something else I just noticed, is that your data is likely to be JSON (the square brackets [] suggest that you have an array of strings).

Neil
  • 11,059
  • 3
  • 31
  • 56