我读取到进程列表,将其导入table,发现有些进程名是有些有后缀名的,有些没有后缀名。
现在想读取字符串中的进程名,有后缀名的,去掉后缀名。有谁能我写个正则表达式。
For Example:
table中的第一列为:QQ.exe,abc.bat,aa,Outlook.exe
得到的结果是:QQ,abc,aa,Outlook
现在想读取字符串中的进程名,有后缀名的,去掉后缀名。有谁能我写个正则表达式。
For Example:
table中的第一列为:QQ.exe,abc.bat,aa,Outlook.exe
得到的结果是:QQ,abc,aa,Outlook
String strPorcess="QQ.exe,abc.bat,aa,Outlook.exe";
strPorcess=strPorcess.replace(".exe","");//此时strPorcess="QQ,abc,aa,Outlook"
return s.SubString(0,s.LastIndexOf('.')>-)
else
return s
{
i++;
string _str = QQ.exe.Substring(0,QQ.exe.Length - i);
}
System.IO.Path.GetFileNameWithoutExtension("abc.bat");
System.IO.Path.GetFileNameWithoutExtension("aa");
System.IO.Path.GetFileNameWithoutExtension("Outlook.exe");
string content = @"Q.Q1.exe,abc.bat,aa,Outlook.exe,";
Regex replaceReg = new Regex(@"\.[^.,]*,");
content = replaceReg.Replace(content, ",");
Console.Write(content);
Console.Read();
{
static void Main()
{
foreach (string s in "QQ.exe,abc.bat,aa,Outlook.exe".Split(','))
{
string t = System.IO.Path.GetFileNameWithoutExtension(s);
System.Console.WriteLine(t);
}
}
}
/* 程序输出:
QQ
abc
aa
Outlook
*/