Sunday, March 21, 2010

Verbatim

Recently, we have discussed verbatim programs with my colleagues. Verbatim program prints itself on the output. I know that we did such a thing at the university in Pascal, but I could remember little of it. Thus I have decided to create one from scratch, although in C#. It took me some time to find a proper quotes escaping, that was the most difficult part of the program I would say. Still it is nice to see that even tough looking problems (initially) may have relatively easy solutions to be reached in a few minutes.

Here comes the source, perhaps not the best of its kind, but working fine.


using System;

namespace Verbatim
{
class Program
{
static void Main(string[] args)
{
const string ap = "\"";
const string s =
@"using System;

namespace Verbatim
{{
class Program
{{
static void Main(string[] args)
{{
const string ap = {1}\{1}{1};
const string s =
@{1}{0}{1};
Console.WriteLine(s, s, ap);
}}
}}
}}";
Console.WriteLine(s, s, ap);
}
}
}

No comments: