c# - Split using regex considering only first occurence of the regex pattern -
here code split string patter based on regex match.
string[] docpath = regex.split("\\\\sds\\dsd\\df\\df\\d\\fd\\d\\sd\\asdsf\\sdf\\d\\dsfsd", @"[\\][a-z][\\]");
the above code splits input string (hardcoded) 3 parts i.e
- \\sds\dsd\df\df\d\fd
- sd\asdsf\sdf
- dsfsd
i want split on first occurrence. output want :
- \\sds\dsd\df\df\d\fd
- sd\asdsf\sdf\d\dsfsd
can please me modify reg expression? kindly help.
use version of regex.split()
that's instance method takes number specifying maximum number of components split into:
regex pattern = new regex(@"[\\][a-z][\\]"); string[] docpath = pattern.split( "\\\\sds\\dsd\\df\\df\\d\\fd\\d\\sd\\asdsf\\sdf\\d\\dsfsd", 2);
Comments
Post a Comment