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

  1. \\sds\dsd\df\df\d\fd
  2. sd\asdsf\sdf
  3. dsfsd

i want split on first occurrence. output want :

  1. \\sds\dsd\df\df\d\fd
  2. 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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -