Maybe this repository will get a new name. When I started this project, I wanted to get some values from the command-line interface. Instead this is also a collection of methods. There is most likely two versions of the same method, a collection of "Gist".
Here is an example: Two versions of the same method. π
/// <summary>
/// Converts dash/underscore delimited words into camel casing.
/// The first word within the output should be capitalized only if the original word was capitalized.
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string ToCamelCase(string str)
{
StringBuilder sb = new StringBuilder();
string tempStr = str;
char lastChar = 'a';
foreach (char character in str)
{
if (character == '-' || character == '_')
{
}
else
{
if (lastChar == '_' || lastChar == '-')
{
sb.Append(character.ToString().ToUpper());
}
else
{
sb.Append(character);
}
}
lastChar = character;
}
return sb.ToString();
}
/// <summary>
/// Same as ToCamelCase, just in one line.
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string ToCamelCase2(string str)
{
return Regex.Replace(str, @"[_-](\w)", m => m.Groups[1].Value.ToUpper());
}
This is how I execute a command through CMD. The string strCommandToCMD could be something like "netsh wlan show networks".
private void ExecuteCMDCommand(string strCommandToCMD)
{
Process cmd = new Process();
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(strCommandToCMD);
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
}
Join CodeWars with me!: www.codewars.com/r/hGyTsQ