Skip to content

Commit

Permalink
Create Source.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
FooqX authored Feb 1, 2022
1 parent 0b38fc3 commit 71a32b2
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Source.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("~~ Text to decimal ASCII v1.0.1");
Console.ResetColor();

// Getting string from user input
Console.Write("Enter the string >> ");
string text = Console.ReadLine();

// Getting seperator from user input
Console.Write("Enter a seperator (char) >> ");
char seperator = Console.ReadKey().KeyChar;

Console.Write("\nConverting to ASCII array... ");
// Creating ASCII array that will store ASCII numbers
uint[] asciiArray = new uint[text.Length];

for (int i = 0; i < text.Length; i++) {
asciiArray[i] = Convert.ToUInt32(text[i]);
}

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\rSuccessfully converted text to ASCII array!");
Console.ResetColor();

Console.Write("Seperating ASCII with custom seperator...");

string output = "";
for (int i = 0; i < text.Length; i++) {
output = output + seperator + asciiArray[i];
}

// A fix for the seperator being at the beginning
if (','.Equals(seperator) || ' '.Equals(seperator)) {
output = output.Remove(0, 1);
}

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\rSuccessfully seperated ASCII with custom seperator!\n");
Console.ResetColor();

if (output.Length >= 150) {
Console.WriteLine("- Output: Too big to show (length greater than 150)");
} else {
Console.WriteLine("- Output: " + output);
}

Console.Write("Copy output to clipboard? (Y)es/(N)o >> ");

if ("y".Equals(Console.ReadLine().ToLower())) {
using System.Diagnostics.Process cmd = new();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();

cmd.StandardInput.WriteLine("echo|set/p=" + output + "|clip");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
cmd.Dispose();
}

Console.WriteLine("Press return to terminate the program;");
Console.ReadKey();
Environment.Exit(0);

0 comments on commit 71a32b2

Please sign in to comment.