M
Michael Lang
original file contents:
;; any alpha string at least 1 char long
[NAMESPACE], "Namespace", "[a-zA-Z].";
;;
;; must start with alpha, can contain numeric or alpha chars only
[CLASSNAME], "Class Name", "[a-zA-Z][a-zA-Z0-9]."
;;
;; must start with alpha, can contain numeric or alpha chars only
[KEYPROPERTY], "Key Property", "[a-zA-Z][a-zA-Z0-9]."
;;
#CODE_TEMPLATE_START
.... more lines here ...
I read this file in with:
System.IO.StreamReader sr = new System.IO.StreamReader(file);
_classTemplate = sr.ReadToEnd();
int iSplitStart = _classTemplate.IndexOf("#CODE_TEMPLATE_START");
_classHeader = _classTemplate.Substring(0, iSplitStart-1);
from locals window in debug mode:
_classHeader = ";; any alpha string at least 1 char long\r\n[NAMESPACE],
\"Namespace\", \"[a-zA-Z].\";\r\n;;\r\n;; must start with alpha, can
contain numeric or alpha chars only\r\n[CLASSNAME], \"Class Name\", \"[a-
zA-Z][a-zA-Z0-9].\"\r\n;;\r\n;; must start with alpha, can contain
numeric or alpha chars only\r\n[KEYPROPERTY], \"Key Property\", \"[a-zA-
Z][a-zA-Z0-9].\"\r\n;;\r"
Now I need to split this header by any line that starts with a comment
marked as ";;". This should give me lines such as:
[NAMESPACE], "Namespace", "[a-zA-Z].";
[CLASSNAME], "Class Name", "[a-zA-Z][a-zA-Z0-9]."
[KEYPROPERTY], "Key Property", "[a-zA-Z][a-zA-Z0-9]."
My regex to do this is:
_rgxHeaderParser = new Regex("^;;", RegexOptions.Multiline
& RegexOptions.Compiled);
I call it like this:
string[] props = _rgxHeaderParser.Split(_classHeader);
I get 2 strings, one is empty, and the other contains the entire contents
of _classHeader. How do I fix this Regex?
Doesn't "\r\n" mean a newline? If not how do I read the file so that
newlines in the file mean newline for a regex? I though the MultiLine
RegexOption would consider "^" as anytime that is the start of a line?
So why is it not splitting each time it finds ";;" at the beginning of a
line?
;; any alpha string at least 1 char long
[NAMESPACE], "Namespace", "[a-zA-Z].";
;;
;; must start with alpha, can contain numeric or alpha chars only
[CLASSNAME], "Class Name", "[a-zA-Z][a-zA-Z0-9]."
;;
;; must start with alpha, can contain numeric or alpha chars only
[KEYPROPERTY], "Key Property", "[a-zA-Z][a-zA-Z0-9]."
;;
#CODE_TEMPLATE_START
.... more lines here ...
I read this file in with:
System.IO.StreamReader sr = new System.IO.StreamReader(file);
_classTemplate = sr.ReadToEnd();
int iSplitStart = _classTemplate.IndexOf("#CODE_TEMPLATE_START");
_classHeader = _classTemplate.Substring(0, iSplitStart-1);
from locals window in debug mode:
_classHeader = ";; any alpha string at least 1 char long\r\n[NAMESPACE],
\"Namespace\", \"[a-zA-Z].\";\r\n;;\r\n;; must start with alpha, can
contain numeric or alpha chars only\r\n[CLASSNAME], \"Class Name\", \"[a-
zA-Z][a-zA-Z0-9].\"\r\n;;\r\n;; must start with alpha, can contain
numeric or alpha chars only\r\n[KEYPROPERTY], \"Key Property\", \"[a-zA-
Z][a-zA-Z0-9].\"\r\n;;\r"
Now I need to split this header by any line that starts with a comment
marked as ";;". This should give me lines such as:
[NAMESPACE], "Namespace", "[a-zA-Z].";
[CLASSNAME], "Class Name", "[a-zA-Z][a-zA-Z0-9]."
[KEYPROPERTY], "Key Property", "[a-zA-Z][a-zA-Z0-9]."
My regex to do this is:
_rgxHeaderParser = new Regex("^;;", RegexOptions.Multiline
& RegexOptions.Compiled);
I call it like this:
string[] props = _rgxHeaderParser.Split(_classHeader);
I get 2 strings, one is empty, and the other contains the entire contents
of _classHeader. How do I fix this Regex?
Doesn't "\r\n" mean a newline? If not how do I read the file so that
newlines in the file mean newline for a regex? I though the MultiLine
RegexOption would consider "^" as anytime that is the start of a line?
So why is it not splitting each time it finds ";;" at the beginning of a
line?