0

I am having a brain-aching problem, which I hope you guys could help.

I have a textBox1 containing multiline string as follow:

filewith.dl_
somefiles.sy_
morewith.ex_

textBox1 contains a files that GetFiles finds when the user browses to a folder containing compressed windows installation files.

What I want to do is have the same multiline text shown in textBox2 but replace .dl_ with .dll, sy_ with sys and ex_ with exe.

I have tried:

    private void buttonExpandAll_Click(object sender, EventArgs e)
    {
        textBox2.Text = textBox1.Text.Replace(".dl_", "dll");
    }

but obviously that is very limiting as it can only replace .dl_ to dll and ignores the other sy_ and dl_.

I have tried Regex.Replace as well but again it only does .dl_ and not the othe two.

Is there a way to replace those characters in one swoop? Sorry if this is simple guys but I am new to this!

thank you in advance!

Nigel

David
  • 15,894
  • 22
  • 55
  • 66
Nigel.Harris
  • 77
  • 2
  • 2
  • 7
  • http://stackoverflow.com/questions/12007358/alternative-to-string-replace-multiple-times – Ydhem Apr 21 '13 at 07:02

1 Answers1

1

A simple way would be to chain calls to Replace like this:

textBox2.Text = textBox1.Text
    .Replace(".dl_", ".dll")
    .Replace(".ex_", ".exe")
    .Replace(".sy_", ".sys");
Dirk
  • 10,668
  • 2
  • 35
  • 49