0

I want to read the response from the URI and modify it by replacing all S's to X's and to return that string back to client. Below is my code, but replace is not working. I downloaded the "response" string to check and there are lots of S characters. Any idea why this is not working or how can I manipulate this ?

try
        {
            // open and read from the supplied URI
            stream = webClient.OpenRead(uri);
            reader = new StreamReader(stream);
            response = reader.ReadToEnd();
            response.Replace('S', 'X');
            webClient.DownloadFile(uri, "C://Users//MyPC//Desktop//a.txt");

        }

Thanks..

Paul R
  • 208,748
  • 37
  • 389
  • 560

1 Answers1

1

you can use webClient.DownloadString(uri)

like this:

string str = webClient.DownloadString(uri).Replace('S', 'X');
            File.WriteAllText(@"C://Users//MyPC//Desktop//a.txt", str);
Tomer Klein
  • 436
  • 2
  • 6
  • Yes, that worked, thanks. By the way my mistake is I didn't assign response.Replace('S', 'X') to a string. Assigning and returning that new string solves that too ;) – marty flying mcfly Jan 01 '15 at 20:00