Skip to content

Instantly share code, notes, and snippets.

@plioi
Created October 21, 2013 19:12
Show Gist options
  • Save plioi/7089264 to your computer and use it in GitHub Desktop.
Save plioi/7089264 to your computer and use it in GitHub Desktop.
static void Message(string format, params string[] args)
{
var encodedArgs = args.Select(Encode).Cast<object>().ToArray();
Console.WriteLine("##teamcity["+format+"]", encodedArgs);
}
static string Encode(string value)
{
var builder = new StringBuilder();
foreach (var ch in value)
{
switch (ch)
{
case '|': builder.Append("||"); break;
case '\'': builder.Append("|'"); break;
case '[': builder.Append("|["); break;
case ']': builder.Append("|]"); break;
case '\n': builder.Append("|n"); break; // Line Feed
case '\r': builder.Append("|r"); break; // Carriage Return
case '\u0085': builder.Append("|x"); break; // Next Line
case '\u2028': builder.Append("|l"); break; // Line Separator
case '\u2029': builder.Append("|p"); break; // Paragraph Separator
default: builder.Append(ch); break;
}
}
return builder.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment