At many times we are required to Split a string with some delimiter. e.g
Rose,Lotus,,Lily
now problem comes if the delimiter has been entered twice (here between Lotus and Lily) on splitting an extra element will be created in array. Now since we do not know how many times the extra delimiter has been entered, we can not use string Replace.
Here Regex Replace comes to our rescue.
Regex exp = new Regex(@",+"); strFlowers = exp.Replace(strOrderOriginal, ",").Trim(); strFlower = strOrder.Trim().Split(',');
Here i am creating a Regex with multiple instances of separator ',' then using Replace to Replace all instances of , or ,, or ,,.., with one ,
|
No responses found. Be the first to respond and make money from revenue sharing program.
|