String question

Ruttensoft
Ruttensoft used Ask the Experts™
on
Hello

I have this string:

\My Computer\Local Disk (C:)\Test\Test.
or:
\My Computer\Programme (D:)\Test2\Test2.

what I want to "extract" out of it, is:
C:\Test\Test
and for the second:
D:\Test2\Test2

How can I do that?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
use indexof  to serch for "("  and then use substring( strating position of "("  ,length of string)

Author

Commented:
Thanks. As there could be more than one '(', can I use indexof to search for the last '('?

string MainString = @"\My Computer\Local Disk (C:)\Test\Test";
string[] Split = MainString.Split(new Char[] { '(' });
 //SHOW RESULT 
MessageBox.Show(Convert.ToString(Split[0]));
MessageBox.Show(Convert.ToString(Split[1]).Remove(2,1));//C:\Test\Test

Open in new window

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial