I have a string:

`{"response":{"count":544271,"items":[358322758,358306517,358297876,358293716,358293542,358285919,358281793,358241319,358239216,358238181]}}` 

I am trying to remove its first part using the replacement method:

 badString.replace("{\"response\":{\"count\":", "aaa"); 

But, as a result, the string does not change, I get the original string! Why is this happening and how to fix it?

    1 answer 1

    The replace method returns a modified string, but does not change it. So you need to assign the result of calling this method to your string.

     badString = badString.replace("{\"response\":{\"count\":", "aaa"); 

    It is also written on the docks:

    Returns a copy of this string after replacing.

    • 2
      ... and continue to use the JSON parser to parse JSON :) - VladD
    • one
      @VladD, useful addition, yes) - YuriySPb
    • @VladD, hmm .... is there such a thing?) - user189127
    • one
      @ bukashka101, yes, there is. Here is an example - JuriySPb
    • 2