Created
September 29, 2022 14:23
-
-
Save ttkoma/7fa1430dd302b569595d42e607648353 to your computer and use it in GitHub Desktop.
TripleEncodingChars
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
public static string TripleEncodeSymbol(this string input, string targetSymbol, string firstSymbol = "$", string secondSymbol = "Z") | |
{ | |
if (targetSymbol == firstSymbol) | |
throw new ArgumentOutOfRangeException($"{nameof(targetSymbol)} can't be equal {nameof(firstSymbol)}"); | |
if (targetSymbol == secondSymbol) | |
throw new ArgumentOutOfRangeException($"{nameof(targetSymbol)} can't be equal {nameof(secondSymbol)}"); | |
//return input.Replace("$", "$$$").Replace("Z", "$$Z").Replace(":", "$ZZ"); | |
return input | |
.Replace(firstSymbol, firstSymbol + firstSymbol + firstSymbol) | |
.Replace(secondSymbol, firstSymbol + firstSymbol + secondSymbol) | |
.Replace(targetSymbol, firstSymbol + secondSymbol + secondSymbol); | |
} | |
public static string TripleDecodeSymbol(this string input, string targetSymbol, string firstSymbol = "$", string secondSymbol = "Z") | |
{ | |
if (targetSymbol == firstSymbol) | |
throw new ArgumentOutOfRangeException($"{nameof(targetSymbol)} can't be equal {nameof(firstSymbol)}"); | |
if (targetSymbol == secondSymbol) | |
throw new ArgumentOutOfRangeException($"{nameof(targetSymbol)} can't be equal {nameof(secondSymbol)}"); | |
//return input.Replace("$ZZ", ":").Replace("$$Z", "Z").Replace("$$$", "$"); | |
return input | |
.Replace(firstSymbol + secondSymbol + secondSymbol, targetSymbol) | |
.Replace(firstSymbol + firstSymbol + secondSymbol, secondSymbol) | |
.Replace(firstSymbol + firstSymbol + firstSymbol, firstSymbol); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment