Quantcast
Channel: CodeProject Latest postings for Regular Expressions
Viewing all articles
Browse latest Browse all 224

part of string before a match

$
0
0
I have a path and I want to get the part of a path before my match:
string s1= @"c:\temp\lev1\lev2\lev3\MYWORD\lev5\lev6";string mtch ="MYWORD"


knowing
s1
and
mtch
I want to get the part of path before mtch, so @"c:\temp\lev1\lev2\lev3\".

I tried with RegEx but I don't know how to be elegant.. I'm only able to find MYWORD position and then use the substring.
Is there a smarter solution?

Viewing all articles
Browse latest Browse all 224

Trending Articles