Search code examples
c#filereplaceoperation

Replace word + xx (unknown ) value using c#


I am trying to do the replace string in the file. I want to replace the word and xyz(unknown) value. Eg. My .java file contains hello hello01 hello03 hello07 hello09 . . . hello99 I want to replace helloXX to hello The XX are random. How to do it using C#?


Solution

  • Best way would be to use a Regex class

    Edit:

            var regex = new Regex(@"hello\d+");
    
            var original = "hello123";
            var updated = regex.Replace(original, "hello");