I need to parse an EDI file where the delimiters are the + ,: and ' signs, and the escape (release) character ? . First you segment
var data = "NAD+UC+ABC2378::92++XYZ Corp.:Tel ?: ?+90 555 555 11 11:Mobile1?: ?+90 555 555 22 22:Mobile2?: ?+90 555 555 41 71+Duzce+Seferihisar / IZMIR++35460+TR" var segments = data.Split('\'');
then each segment is divided into segment data elements by + , then segment data elements are divided into component data elements through :
var dataElements = segments[0].Split('+');
the above example line is not being processed correctly due to the use of the release character. I have special code related to this, but I think that all this can be done with
Regex.Split(data, separator);
I am not familiar with Regex'es and could not find a way to do this so far. The best I've come up with is
string[] lines = Regex.Split(data, @"[^?]\+");
which lowers the character to the + sign.
NA U ABC2378::9 +XYZ Corp.:Tel ?: ?+90 555 555 11 11:Mobile1?: ?+90 555 555 22 22:Mobile2?: ?+90 555 555 41 7 Duzc Seferihisar / IZMI +3546 TR
The correct result should be:
NAD UC ABC2378::92 XYZ Corp.:Tel ?: ?+90 555 555 11 11:Mobile1?: ?+90 555 555 22 22:Mobile2?: ?+90 555 555 41 7 Duzce Seferihisar / IZMIR 35460 TR
So, the question is what can be done with Regex.Split and what should the regular expression separator look like.
c # regex
hazimdikenli
source share