How to find and replace all occurrences of a substring in a string with C#

1 Answer

0 votes
using System;

public class FindAndReplaceAllOccurrencesOfASubstringInAString_CSharp
{
    public static void Main(string[] args)
    {
        string str = "java php go c python php phpphphp php rust";
        string word = "php";
        string replacewith = "C#";

        str = str.Replace(word, replacewith);

        Console.WriteLine(str);
    }
}


 
/*
run:
    
java C# go c python C# C#C#hp C# rust
       
*/

 



answered Aug 25, 2024 by avibootz
...