Finding a process name from an address.  
Author Message
Sacristy





PostPosted: Visual C# Language, Finding a process name from an address. Top

If i have a string that contains an address to a program, or other file, how can i remove the address up until the point of the file
I've tried using the substring method, but that only works up to a point.
I can remove the drive letter and semicolon, but then it doesn't remove the backwards slash.
So far i have:

private void buttonLoad_Click(object sender, EventArgs e)
{
string processName = label3.Text; // label that stores the application path.


int length = ( processName.Length - 2 );
MessageBox.Show("Index " + index +", Length " + length + Environment.NewLine + processName.Substring(index, length));
processName = processName.Substring( ( index) , length);

while (index >= 0)
{

length = processName.Length;
MessageBox.Show("Index " + index + ", Length " + length + Environment.NewLine + processName);
processName = processName.Substring((index), (length));
MessageBox.Show(processName);
index = -1;
}
}

with the final index = -1 so that the while loop only runs once until i work it out.
also, those messageboxes are simply to help me keep track of the program.

Any help will be much appreciated.
Thank you.



Visual C#9  
 
 
Paul Louth





PostPosted: Visual C# Language, Finding a process name from an address. Top

string fileName = System.IO.Path.GetFileName(processName);