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

Johan

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);

            MessageBox.Show(newOne);
}

The output is Word.

Thanks to everyone for helping me out.

Johan

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

Hello

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

Johan

Be a part of the DaniWeb community

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