Created
June 17, 2014 12:24
-
-
Save Spaider/e60d7cca99c875a1d411 to your computer and use it in GitHub Desktop.
Simple template-base generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Reflection; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ | |
private static int Main(string[] args) | |
{ | |
if (args.Length < 2) | |
{ | |
Console.WriteLine("Usage:"); | |
Console.WriteLine(" {0} <path to template> <path to source file>", Path.GetFileName(Assembly.GetEntryAssembly().Location)); | |
Console.WriteLine(); | |
return 1; | |
} | |
var str = File.ReadAllText(args[0]); | |
var strBuilder = new StringBuilder(str); | |
using (var streamReader = new StreamReader(args[1])) | |
{ | |
while (!streamReader.EndOfStream) | |
{ | |
var a = streamReader.ReadLine(); | |
if (!string.IsNullOrWhiteSpace(a)) | |
{ | |
var str1 = "$" + Regex.Replace(a, @":\s((\S|\s)*)", String.Empty) + "$"; | |
var str2 = Regex.Replace(a, @"((\S|\s)*):\s*", String.Empty); | |
strBuilder.Replace(str1, str2); | |
} | |
if (!string.IsNullOrWhiteSpace(a) && !streamReader.EndOfStream) continue; | |
Console.WriteLine(strBuilder); | |
strBuilder = new StringBuilder(str); | |
} | |
} | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment