Last active
June 5, 2019 12:09
-
-
Save TheTrigger/6efa6a8e42eedf1e61e0db8e9ef4360a to your computer and use it in GitHub Desktop.
C# snippet to display ctrl chars
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.Text; | |
namespace CtrlCharReplace | |
{ | |
public static class Extensions | |
{ | |
public static string ReplaceCtrl(this string s) | |
{ | |
var sb = new StringBuilder(); | |
for (int i = 0; i < s.Length; i++) | |
{ | |
char c = s[i]; | |
var isCtrl = char.IsControl(c); | |
var n = char.ConvertToUtf32(s, i); | |
if (isCtrl) | |
{ | |
sb.Append($"\\u{n:X4}"); | |
} | |
else | |
{ | |
sb.Append(c); | |
} | |
} | |
return sb.ToString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment