I have a list and want to run each item in ListViewItem through command line. Currently it seems to me that my list is propagating each item with a space before the text which causes Command Line to not recognize the strings as valid data. How can i remove the whitespace at the beginning and end of each string value in my list?
NOTE: You can see how the list is structured in the area notated as STAGE2
private void wifiButton_Click(object sender, EventArgs e)
{
// STAGE 1 -- Query wifi profiles saved on device and isolate SSIDs
Process cmd = new Process();
cmd.StartInfo.FileName = "netsh.exe";
System.Threading.Thread.Sleep(50);
cmd.StartInfo.Arguments = "wlan show profiles";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.Start();
//* Read the output (or the error)
string output = cmd.StandardOutput.ReadToEnd();
textBox3.Text = output;
cmd.WaitForExit();
System.Threading.Thread.Sleep(50);
// output would be set by earlier code
// STAGE 2 remove extra data in string down to the SSID name, then add insividual results into a list
var regex = new Regex(@" User Profile\s+:(.*)");
var resultList = new List<string>();
foreach (Match match in regex.Matches(output))
{
output = string.Concat(output.Split(' '));
resultList.Add(match.Groups[1].ToString());
textBox4.Items.Add(match.Groups[1].ToString());
}
System.Threading.Thread.Sleep(500);
// STAGE 3 For each item in the list created in stage 2, run individual SSID name through netsh and add results to textbox5.
foreach (ListViewItem item in textBox4.Items)
{
//arg = arg.Remove(0, 15);
Process cmd2 = new Process();
cmd2.StartInfo.FileName = "netsh.exe";
cmd2.StartInfo.Arguments = "wlan show profiles name=" + item;
cmd2.StartInfo.UseShellExecute = false;
cmd2.StartInfo.RedirectStandardOutput = true;
cmd2.StartInfo.RedirectStandardError = true;
cmd2.Start();
//* Read the output (or the error)
string output2 = cmd2.StandardOutput.ReadToEnd();
textBox5.Text += output2;
cmd2.WaitForExit();
}
}