Created
February 17, 2020 21:05
-
-
Save daniel-chenery/8e30769a0bbca4bf46ca3e0313428c71 to your computer and use it in GitHub Desktop.
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.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