Hi Everyone

I need some help. I would like to remove characters from a string that are contained in brackets. For example string (Hello)World, I want to remove the (Hello) part. Is there a way. I can't solve it with the replace or remove methods. I am new to C# and some help would be great.

Thank you


Recommended Answers

All 7 Replies

Perhaps have a look at(to use with Remove) the IndexOf('(') and LastIndexOf(')') methods.
Also the SubString method can be helpfull.
Look up the details here: http://msdn.microsoft.com/en-us/library/system.string_members(v=VS.90).aspx

Thanks I'll give it a try

Thanks @nmaillet too :)

I did something like this to solve my problem. Maybe it helps someone else.

private void btnRemove_Click(object sender, EventArgs e)
            String strTest = "(Test)Word";

            int iS = strTest.IndexOf('(');

            int jS = strTest.LastIndexOf(')');

            String newOne = strTest.Remove(iS, jS + 1);


The output is Word.

Thanks to everyone for helping me out.


What happens when you have "(Test)Word(Broken)"?


Didn't think about it. In my case there's only one bracketed word so that will do just fine :)


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.