Otherwise, you need to know beforehand the template of the file format: the length of the "line" and each "field", its position, length and format within that line. I thought that a concept of a line template, containing one or more field templates, helps a programmer to visualize the structure of the file and makes it easier to extend functionality for more complex tasks. The parser takes an instance of a LineTemplate and can process either the whole file at once or line by line, which allows you to swap different templates for files with complex data structure.
Alternatively, you can iterate through an array of parsed lines. Each ParsedLine object contains a dictionary of ParsedField. All of the parsing logic is concentrated in ParsedField class.
The library contains a handful of classes listed below. First of all, you will need to create a LineTemplate for the file you intend to parse. When you make an instance of a LineTemplate class, you'll have to provide the line length how many bytes per line and a name anything that makes sense to you.
In addition, line template contains a dictionary of type FieldTemplate. Line template must contain at least one field template for the parser to work. Each field must have a unique name, but their positions may overlap if required.
FieldTemplate class has two constructors. Overloaded constructor takes an extra parameter: int decimalPlaces , used by packed and numerical field types.
By default, decimalPlaces equals zero. I need to give citation of the original author of the Unpack method, but I could not find the original source. Please let me know if you find out where this code came from. ParsedLine contains a dictionary or parsed fields as well as means of accessing them. It only has a few public methods and a single public property called Lines which gives you an array of type ParsedLine.
Finally, to run a program, we create an instance of a LineTemplate class, add several FieldTemplate objects to it and pass it on to EbcdicParser. Then, we can access an array of ParsedLine via Lines property and read every field within that line. Parser is rather quick. It takes a few seconds to parse source files which may be hundreds of megabytes in size. Sign in Email. Forgot your password? Search within: Articles Quick Answers Messages. Tagged as C.
Stats K views. Max Vagner Rate me:. Please Sign up or sign in to vote. Download source - Background Our daily operation heavily depends on multiple feed files received from a mainframe. Using the Code I thought that a concept of a line template, containing one or more field templates, helps a programmer to visualize the structure of the file and makes it easier to extend functionality for more complex tasks.
Copy Code. Max Vagner Web Developer. First Prev Next Packed Bytes which doesn't fall under positive, negative or unsigned doesn't get unpacked Member Apr Max Vagner Apr Member Apr Member Jun Max Vagner Nov Member 9-Oct Max Vagner Oct Member Jan Member Nov Member 4-Aug Max Vagner Jun Go to top. Layout: fixed fluid. Web Developer. First Prev Next. Packed Bytes which doesn't fall under positive, negative or unsigned doesn't get unpacked Member Apr Member I'm trying to unpack 8 bytes of field which doesn't falls under positive, negative or unsigned eg.
Re: Packed Bytes which doesn't fall under positive, negative or unsigned doesn't get unpacked Max Vagner Apr Packed number can only have "C", "D", of "F" in the last nibble. All other hex values should be 0 to Re: Packed Bytes which doesn't fall under positive, negative or unsigned doesn't get unpacked Member Apr SO as you said S 18 is not packed or do I need to unpack 8 bytes differently.
Do you know what that field is supposed to be? Is it a number, date or some binary data? What is your expected output? When people say "packed" number it's usually meant COMP-3 packed number.
Replace "G", "7" ; strAmount. Replace "P", "7" ; strAmount. Replace "H", "8" ; strAmount. Replace "Q", "8" ; strAmount. Replace "I", "9" ; strAmount. TryParse strAmount. Simon Chadwick Simon Chadwick 1, 6 6 silver badges 12 12 bronze badges. Parse num, NumberStyles. AllowLeadingWhite NumberStyles. AllowTrailingWhite ;. Lucero Lucero Your suggestion would be okay and quite correct for character data, but alas not at all good for numerical data, since it would change the numbers with the new character mapping.
That's also why I wrote the bottom paragraph about not being sure whether this actually answers the question at hand. As long as the title is left unchanged I'll leave my answer here for others which are searching for EBCDIC character conversion and come across this question, but I'll be happy to delete it when the title and question text are clearer.
Indeed, it is a great answer for converting between the character encodings. Trim ; if trimmed. ToChar trimmed. Substring trimmed. Parse trimmed. Substring 0, trimmed. Abs value. Substring 0, str. Generic; using System. Linq; using System. Text; using System. AwayFromZero : MidpointRounding. MaxValue is and that would only give us 10 digits to work with.
MaxValue vs ulong. MaxValue is one digit shorter. Pow 10, length - 1 throw new ArgumentException "Value exceeds specified total number of fixed digits. Blake Blake 2 2 silver badges 10 10 bronze badges. Try following function.. Substring i, 1 ; sb. Append Convert. WriteLine ex. Message ; return string. Vivek Jagga Vivek Jagga 1 1 gold badge 5 5 silver badges 13 13 bronze badges.
First link is broken. Third link is broken. Fourth link refers to third link. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses.
Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked Related Hot Network Questions.
Question feed.
0コメント