Fixed length strings or structures in C#

后端 未结 3 2099
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 02:32

I need to create a structure or series of strings that are fixed lenght for a project I am working on. Currently it is written in COBOL and is a communication application. I

3条回答
  •  余生分开走
    2021-01-15 02:50

    You could use the VB6 compat FixedLengthString class, but it's pretty trivial to write your own.

    If you need parsing and validation and all that fun stuff, you may want to take a look at FileHelpers which uses attributes to annotate and parse fixed length records.

    FWIW, on anything relatively trivial (data processing, for instance) I'd probably just use a ToFixedLength() extension method that took care of padding or truncating as needed when writing out the records. For anything more complicated (like validation or parsing), I'd turn to FileHelpers.

提交回复
热议问题