0

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

4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by johang_80
0

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

0

Hello

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

Johan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.