比如说我的picturebox2.image=2.jpg;picturebox1.image可能是三张图片的任意一张,假如两个picturebox的图片一样,就消失,如何实现?

解决方案 »

  1.   


                string s = "2.jpg";
                MessageBox.Show(s.Substring(0,s.IndexOf('.')));
      

  2.   

       string str = "1.jpg,2.jpg,3.jpg";
                string pattern = @"\d(?=\.\w)?";
                Regex regex = new Regex(pattern);
                MatchCollection mc = regex.Matches(str);
                foreach (Match m in mc)
                Console.WriteLine(m.Value);
      

  3.   

    foreach (Match m in mc)
    =>
    foreach (Match m in mc.Cast<Match>().Distinct())
    可以去除重复的。
      

  4.   


                string str = "1.jpg,2.jpg,3.jpg";
                string pattern = @"\d(?=\.\w)?";
                Regex regex = new Regex(pattern);
                MatchCollection mc = regex.Matches(str);
                foreach (Match m in mc)
                    Console.WriteLine(m.Value);
                /*
                 * 1
                 * 2
                 * 3
                 * */
      

  5.   

    LZ 为什么不判断picturebox.image是否相等那?图片前面的一样,并不代表后缀也一样呀,这样可能也不是同一个图片的
      

  6.   

                string str = "1.jpg,22.jpg,3.jpg";
                Regex reg = new Regex(@"\d+");
                foreach (Match m in reg.Matches(str))
                {
                    Response.Write(m.Value + "<br/>");
                }
      

  7.   

                string str = "1.jpg,22.jpg,1.jpg,3.jpg,,22.jpg,3.gif,4.jpg";
                Regex reg = new Regex(@"([^,]+)(?!.*?\1)");
                foreach (Match m in reg.Matches(str))
                {
                    Response.Write(m.Value + "<br/>");
                }
    /*
    1.jpg
    3.jpg
    22.jpg
    3.gif
    4.jpg
    */
      

  8.   

    Random  rand=new Random();
    string str1=“2.jpg”;
    int init=rand.Next(1,3)
    picturebox2.image=str1;
    imagepicturebox1.image=“\“"+init+".jpg\"";
    Console.WriteLine(str1.Substring(0,s.IndexOf('.')));
    Console.WriteLine(init);