Skip to content

Instantly share code, notes, and snippets.

@daniel-chenery
Created February 17, 2020 21:05
Show Gist options
  • Save daniel-chenery/8e30769a0bbca4bf46ca3e0313428c71 to your computer and use it in GitHub Desktop.
Save daniel-chenery/8e30769a0bbca4bf46ca3e0313428c71 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Program
{
public static void Main()
{
const string Content = "Hello World";
var bytes = Encoding.UTF8.GetBytes(Content);
var base64 = Convert.ToBase64String(bytes);
var jsonBuilder = new StringBuilder();
jsonBuilder.Append("[");
foreach(var b in bytes)
{
jsonBuilder.Append(b);
jsonBuilder.Append(",");
}
jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
jsonBuilder.Append("]");
var json = jsonBuilder.ToString();
Console.WriteLine($"{jsonBuilder} ({jsonBuilder.Length})");
Console.WriteLine($"{base64} ({base64.Length})");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment