0

I'm getting a string from a Json :

var value = JsonObject["price"]; //value = "1,560";

i'm trying to replace the ',' with an empty string :

value.Replace(",",string.Empty);

but i'm still getting the value with "," that's so strange and i'm stuck at it

thanks in advance

  • 1
    Are you using the returned value? You should have `value = value.Replace(",", string.Empty);` – user1304444 Aug 01 '17 at 20:58
  • Yup. C# Strings are immutable. The String Class methods cannot modify the initial string. They can only create and return a new modified version of it. – Andrew Cottrell Aug 01 '17 at 21:08

2 Answers2

4
value = value.Replace( ", ", string.Empty);

strings in .net are immutable.

Tanveer Badar
  • 5,438
  • 2
  • 27
  • 32
3

Per the documentation for String.Replace:

Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string.

It gives you a new string; it doesn't modify the existing one. So you need to assign the result to a variable:

value = value.Replace(",", string.Empty);