How to replace "http:" with "https:" in a string with C#?
c#
Solution
The problem is your strings are in a collection, and since strings are immutable you can't change them directly. Since you didn't specify the type of `links` (`List`? `Array`?) the right answer will change slightly. The easiest way is to create a new list:
links = links.Select(link => link.Replace("http://","https://")).ToList();
However if you want to minimize the number of changes and can access the string by index you can just loop through the collection:
for(int i = 0; i < links.Length; i++ )
{
links[i] = links[i].Replace("http://","https://");
}
Problem
I've stored all URLs in my application with "http://" - I now need to go through and replace all of them with "https:". Right now I have: ``` foreach (var link in links) { if (link.Contains("http:")) { /// do something, slice or replace or what? } } ``` I'm just not sure what the best way to update the string would be. How can this be done?