C#: Loop over Textfile, split it and Print a new Textfile
I get many lines of String as an Input that look like this.
@VAR;Variable=Speed;Value=Fast;Op==;@ENDVAR;@VAR;Variable=Fabricator;Value=Freescale;Op==;@ENDVAR;
I split it, to remove the unwanted fields, like @VAR,@ENDVAR and Op==. The
optimal Output would be:
Speed = Fast;
Fabricator = Freescale; and so on.
I am able to cut out the @VAR and the@ENDVAR. Cutting out the "Op==" wont
be that hard, so thats now not the main focus of the question. My biggest
concern right now is,thatI want to print the Output as a Text-File. To
print an Array I would have to loop over it. But in every iteration, when
I get a new line, I overwrite the Array with the current splitted string.
I think the last line of the Inputfile is an empty String, so the Output I
get is just an empty Text-File. It would be nice if someone could help me.
string[] w ;
Textwriter tw2;
foreach (EA.Element theObjects in myPackageObject.Elements)
{
theObjects.Type = "Object";
foreach (EA.Element theElements in PackageHW.Elements)
{
if (theObjects.ClassfierID == theElements.ElementID)
{
t = theObjects.RunState;
w = t.Replace("@ENDVAR;", "@VAR;").Replace("@VAR;", ";").Split(new
string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in w)
{
tw2.WriteLine(s);
}
}
}
}
No comments:
Post a Comment