I have a line as shown below which is split by pipes. it has double quotes around the string (for example: "ANI").
How do I split this into a separator of channels (which are not included in double quotes)?
511186|"ANI"|"ABCD-102091474|E|EFG"||"2013-07-20 13:47:19.556"
And separable shoule values will look like this:
511186 "ANI" "ABCD-102091474|E|EFG" "2013-07-20 13:47:19.556"
Any help would be appreciated!
EDIT
The answer I accepted did not work for those strings that have double quotes inside. Any idea what the problem is?
using System.Text.RegularExpressions; string regexFormat = string.Format(@"(?:^|\{0})(""[^""]*""|[^\{0}]*)", '|'); string[] result = Regex.Matches("111001103|\"E\"|\"BBB\"|\"XXX\"|||10000009|153086649|\"BCTV\"|\"REV\"|||1.00000000|||||\"ABC-BT AD\"|\"\"\"ABC - BT\"\" AD\"|||\"N\"||\"N\"|||\"N\"||\"N",regexFormat) .Cast<Match>().Select(m => m.Groups[1].Value).ToArray(); foreach(var i in result) Console.WriteLine(i)
source share