Reputation: 77
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
Upvotes: 0
Views: 1699
Reputation: 10968
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");
Upvotes: 1