It's not that simple. The second parameter of String.Substring
is the length not the end-index. You also have to to check if the index is >= 0 and use String.IndexOf
with the overload that takes the start-index to find the correct end-index:
string selected = "blabla(bla)";
string bla = selected;
int index = selected.IndexOf('(');
if(index++ >= 0) // index++ because you want to omit (
{
int endIndex = selected.IndexOf(')', index); // index is start-index to find )
if (endIndex >= 0)
{
bla = selected.Substring(index, endIndex - index); // endIndex - index -> Length
}
}