我读取到进程列表,将其导入table,发现有些进程名是有些有后缀名的有些没有后缀名。
现在想读取字符串中的进程名,有后缀名的,去掉后缀名。有谁能我写个正则表达式。
For Example:
table中的第一列为:QQ.exe,abc.bat,aa,Outlook.exe
得到的结果是:QQ,abc,aa,Outlook

解决方案 »

  1.   

    取后四位,看是不是.exe就行了啊,是的话就去掉
      

  2.   

    不需要用正则表达时啊
    String strPorcess="QQ.exe,abc.bat,aa,Outlook.exe";
    strPorcess=strPorcess.replace(".exe","");//此时strPorcess="QQ,abc,aa,Outlook"
      

  3.   

    这个...不要用正则了吧,Repalace吧
      

  4.   

    if(s.LastIndexOf('.')>-1)
    return s.SubString(0,s.LastIndexOf('.')>-)
    else 
    return s
      

  5.   

    int i = QQ.exe.indexof(".");if(i > -1)
    {
       i++;
       string _str = QQ.exe.Substring(0,QQ.exe.Length - i);
    }
      

  6.   

    System.IO.Path.GetFileNameWithoutExtension("QQ.exe");
    System.IO.Path.GetFileNameWithoutExtension("abc.bat"); 
    System.IO.Path.GetFileNameWithoutExtension("aa"); 
    System.IO.Path.GetFileNameWithoutExtension("Outlook.exe"); 
      

  7.   

    如果用正则表达式而且你确保是用,分开的:
    string content = @"Q.Q1.exe,abc.bat,aa,Outlook.exe,";
                Regex replaceReg = new Regex(@"\.[^.,]*,");
                content = replaceReg.Replace(content, ",");
                Console.Write(content);
                Console.Read();
      

  8.   

    class Demo
    {
      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
    */