Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Last active October 6, 2020 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdanyow/37178ad14f44ee1e66cbeb36416945bb to your computer and use it in GitHub Desktop.
Save jdanyow/37178ad14f44ee1e66cbeb36416945bb to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
</head>
<body>
<h1>Hello world!</h1>
<pre><code id="output"></code></pre>
<script>
// code from a code block in a Docs conceptual article
const docsCodeBlockContent = `// TrimStart examples
string lineWithLeadingSpaces = " Hello World!";
string lineWithLeadingSymbols = "$$$$Hello World!";
string lineWithLeadingUnderscores = "_____Hello World!";
string lineWithLeadingLetters = "xxxxHello World!";
string lineAfterTrimStart = string.Empty;
// Make it easy to print out and work with all of the examples
string[] lines = { lineWithLeadingSpaces, lineWithLeadingSymbols, lineWithLeadingUnderscores, lineWithLeadingLetters };
foreach (var line in lines)
{
Console.WriteLine($"This line has leading characters: {line}");
}
// Output:
// This line has leading characters: Hello World!
// This line has leading characters: $$$$Hello World!
// This line has leading characters: _____Hello World!
// This line has leading characters: xxxxHello World!
// A basic demonstration of TrimStart in action
lineAfterTrimStart = lineWithLeadingSpaces.TrimStart(' ');
Console.WriteLine($"This is the result after calling TrimStart: {lineAfterTrimStart}");
// This is the result after calling TrimStart: Hello World!
// Since TrimStart accepts a character array of leading items to be removed as an argument,
// it's possible to do things like trim multiple pieces of data that each have different
// leading characters,
foreach (var lineToEdit in lines)
{
Console.WriteLine(lineToEdit.TrimStart(' ', '$', '_', 'x'));
}
// Result for each: Hello World!
// or handle pieces of data that have multiple kinds of leading characters
var lineToBeTrimmed = "__###__ John Smith";
lineAfterTrimStart = lineToBeTrimmed.TrimStart('_', '#', ' ');
Console.WriteLine(lineAfterTrimStart);
// Result: John Smith`
// Skeleton program for try.dot.net
const tryDotNetScaffolding = `using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Text.RegularExpressions;
namespace Program
{
class Program
{
static void Main(string[] args)
{
#region controller
____
#endregion
}
}
}`
// compose the code block with the scaffolding... what the heck??? where does the #endregion inside the for-loop come from?
const program = tryDotNetScaffolding.replace('____', docsCodeBlockContent);
output.textContent = program;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment