I am trying to split a string in c#. I am receiving a string with multiple whitespaces and i want to split it at the whitspaces. So far all I have tried failed. It is not throwing an error put the string simply stays empty
using System;
using System.Diagnostics;
using System.Management;
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out int ProcessId);
public static Process GetActiveWindowProcess(){
var processWithFocus = GetForegroundWindow();
int processId;
GetWindowThreadProcessId(processWithFocus, out processId);
Process process = Process.GetProcessById(processId);
return process;
}
public static String getCommandLine(){
string wmiQueryString = "SELECT * FROM Win32_Process WHERE ProcessId = " + process.Id;
using (var searcher = new ManagementObjectSearcher(wmiQueryString))
{
using (var results = searcher.Get())
{
ManagementObject mo = results.Cast<ManagementObject>().FirstOrDefault();
if (mo != null)
{
String str = (string)mo["CommandLine"];
Debug.WriteLine(str.Split(' ')); //Splitting the string
return str;
}
}
}
}
I tried all of the methods I could find yet the result is the same. The string is there but the string array is empty.
var ssizes = myStr.Split(" \t".ToCharArray());
string[] ssize = myStr.Split(null);
string[] ssize = myStr.Split(new char[0]);
//all arrays are emtpy...
Am I missing out something?
EDIT Sorry the error was on my Site. Debug does not output the Array. I have mistaken it to be empty.