Introduction
Sometimes it's necessary to create large string variables in code. One recent example I was working on was a project whose database component was "self healing" (i.e., if any of the necessary tables were missing, the application would automatically recreate them). Creating and concatenating these large strings can be dull, cumbersome, and is prone to error. Since the table creation scripts could easily be saved to a file, I wrote this utility to process the text file into a code string. I've also used it for HTML snippets and JavaScript code for web controls.
Using the Utility
After selecting a source file to use, you can select a code format output, C#, VB.NET and VB6.
There are several other output options, such as preserving white space and blank lines.
To make the generated code more useful, you can add text before and after the source file. I commonly use this to define method signatures and return values respectively. You can also add text to the string variable before and after the source file. Once you've defined how you want the file processed, just run the utility to see the output. You can then right-click on the output textbox and either copy the results to the clipboard or save it to a file.
I've tried to add some convenient items to the utility, such as, the default file extension for saving the result matches the selected code output (i.e., ".cs" for C#, etc.). Also, each label has a tool tip to help explain the usage of the item.
The code that runs this application is fairly simple, processing the basic defined rules and interacting through the lines in the file. I've attempted to make the code as modular as possible if you wanted to add another language output.
I'd love to hear any suggestions on making this utility even more useful, but until then, I hope you find this as handy as I have.