marty flying mcfly
marty flying mcfly

Reputation: 1

C# WebClient StreamReader string replace not working

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..

Upvotes: 0

Views: 467

Answers (1)

Tomer Klein
Tomer Klein

Reputation: 446

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);

Upvotes: 1

Related Questions