Replace a text character

Good day.
I am trying to replace a text character from a file with another character
Here is the code:

        string s = TextMP1.text;
        var word = "    ";
        var replaceTo = "- ";
        var words = new Regex(word).Matches(s).OfType<Match>().Select(match => match.Index).ToList();
        var result = s.Substring(0, words[0]) + replaceTo + s.Substring(words[0] + word.Length);

Nothing works, what should I do?

Can’t you just use the string.Replace Method? String.Replace Methode (System) | Microsoft Learn

1 Like

thank
Working code:

string text = TextMP.text;
TextMP.text = text.Replace("    ", "-");